I have installed the "yarn add react#experimental react-dom#experimental",and use the unstable_createRoot,but have the error with start.
this is my index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.unstable_createRoot(document.getElementById('root')).render(<App/>);
the result :
Uncaught TypeError: react_dom__WEBPACK_IMPORTED_MODULE_1___default.a.unstable_createRoot is not a function
so help it work
Related
I have an app that works well locally. But on production, I am getting this error.
enter image description here
enter image description here
I thought it is related to webpack but could not find any clue. I am stuck with that.
import React from 'react';
import ReactDOM from 'react-dom';
import moment from 'moment';
import * as styled from 'styled-components';
import NotificationContext from 'og-merchant-portal-react-library/lib/NotificationContext/NotificationContext';
import FetchContext from 'og-merchant-portal-react-library/lib/FetchContext';
import { UserInfoContext } from 'og-merchant-portal-react-library';
import App from './App';
import { unregister } from './serviceWorker';
window.IngenicoLib = {
React,
ReactDOM,
moment,
NotificationContext,
FetchContext,
UserInfoContext,
'styled-components': styled,
};
I am getting the following error when trying to display the modal:
My code is the following:
What i am doing wrong?
The mistake is in import statment.
Replace
import {ReactDOM} from 'react-dom'
with
import ReactDOM from "react-dom"
Reason : As there is no named export of ReactDOM from "react-dom", it is not imported and the reference will be undefined. So, you are getting the error. ReactDOM is default export.
UPDATE
Replace
import {ReactDOM} from 'react-dom'
with
import ReactDOM from "react-dom/client"
Reason : Now react does't support importing ReactDOM from react-dom instead it supports importing ReactDOM from react-dom/client
For react v18 and above the import statement does have client included
so replacing
import {ReactDOM} from 'react-dom'
with
import ReactDOM from 'react-dom/client';
is advised
as per docs on react portals
I am trying to use react suspense but I am facing some issue regarding rendering after making changes in react index.js file and I already installed react suspense "npm install react#experimental react-dom#experimental"
My index.js file
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
Index.js file
Error
TypeError: react_dom__WEBPACK_IMPORTED_MODULE_1___default.a.createRoot is not a function
Error Image
To anyone updating an old React App, the React support doc on React 18 says to write ONLY:
npm install react react-dom
for the React 18 update.
I had two React 16 apps I wanted to update.
To do so, I first updated to React 17:
npm install react#17.0.0 react-dom#17.0.0
ONLY AFTER this version is installed properly, you are able to install to 18, specifying the version in the installation command:
npm install react#18.0.0 react-dom#18.0.0
After that,
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
works just fine.
Follow the version update on your 'package,json' file.
In order to works is required to use ReactDOM.unstable_createRoot
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.unstable_createRoot(document.getElementById("root")).render(<App />);
change -> import ReactDOM from "react-dom";
to -> import ReactDOM from "react-dom/client";
I have structured everything properly. But while compiling react keep on says module not found how to fix?
Module not found: Can't resolve 'ui-config/themes' in 'C:\Users\Goodwork\desktop\mihy-ui-framework\src'
this is my index file
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from "react-router-dom";
import { MuiThemeProvider, createMuiTheme } from '#material-
ui/core/styles';
import { Provider } from 'react-redux';
import store from 'ui-redux/store';
import './index.css';
import App from 'ui-views/App';
import registerServiceWorker from './registerServiceWorker';
import themeObject from "ui-config/themes";
Unless you have configured webpack with resolve alias ui-config, it's not going to work because webpack looks for npm module called ui-config in node_modules.
To fix it,
Add to your webpack configuration the following:
resolve: {
alias: {
'ui-config: 'relative-path-to-ui-config'
}
}
alternatively, you can adjust the relative path in your import
import themeObject from "./ui-config/themes";
This is less optimal because eventually you'll end up struggeling with nested folders import '../../../../../' to find ui-config relative path.
Trying to use react-data-tables here and getting errors left right and center. Going crazy.
After following the instructions as per https://github.com/adazzle/react-data-grid and using the code samples from http://adazzle.github.io/react-data-grid/examples.html#/filterable-sortable-grid I am having the following issues.
If I use this in my file
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDataGrid from 'react-data-grid';
import ReactDataGridPlugins from 'react-data-grid/addons';
var Toolbar = ReactDataGridPlugins.Toolbar;
var Selectors = ReactDataGridPlugins.Data.Selectors;
I get a "Cannot read property 'Toolbar' of undefined.
If I try
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDataGrid from 'react-data-grid';
import Toolbar from 'react-data-grid/addons';
import Selectors from 'react-data-grid/addons';
I get the following error:
React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of HostProviderList.
And if I try
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDataGrid from 'react-data-grid';
import {Toolbar} from 'react-data-grid/addons';
import {Selectors} from 'react-data-grid/addons';
I get this error
Warning: Unknown props onGridSort, columns, rowGetter, rowsCount, minHeight, onRowUpdated, toolbar, onAddFilter, minColumnWidth, columnEquality, enableCellSelect, rowHeight, enableRowSelect, rowKey, rowScrollTimeout, cellNavigationMode, headerRows, columnMetrics, cellMetaData, selectedRows, rowSelection, expandedRows, rowOffsetHeight, sortColumn, sortDirection, onSort, totalWidth, onViewportKeydown, onViewportKeyup, onViewportDragStart, onViewportDragEnd, onViewportDoubleClick, onColumnResize on tag. Remove these props from the element.
I am not sure what to do here. If I do just the basic data-grid as per the online example it works fine. However as soon as I try anything with the addons.jsx file it fails.
On a side note
nmp install react-data-grid/addons
does not work. The git repo is not found. However I do see that after doing an npm install of react-data-grid I do have a addons.jsx file that imports dist/react-data-grid.ui-plugins.js
The right way to import is
import { Toolbar, Data } from 'react-data-grid/addons';
const Selectors = Data.Selectors;