I'm new to coding so I'm following this tutorial: https://www.sitepoint.com/react-tutorial-build-calculator-app/ I can't render any elements. This is what the console displays when running a web application
This is my App.js code:
import Wrapper from "./components/Wrapper.js"; import Screen from "./components/Screen.js"; import ButtonBox from "./components/ButtonBox.js"; import Button from "./components/Button.js"; const btnValues = [ ["C", "+-", "%", "/"], [7, 8, 9, "X"], [4, 5, 6, "-"], [1, 2, 3, "+"], [0, ".", "="], ]; const App = () => { return ( <Wrapper> <Screen value="0" /> <ButtonBox> { btnValues.flat().map((btn, i) => { return ( <Button key={i} className={btn === "=" ? "equals" : ""} value={btn} onClick={() => { console.log(`${btn} clicked!`); }} /> ); }) } </ButtonBox> </Wrapper> ); }; export default App;
Then this is index.js:
import React from 'react'; import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById("root") );
Try specifying the root element like this:
Judging from the error message in the console, there seems to be a problem with the import statement in the index.js file. The error specifically states that ReactDOM is imported from "react-dom/client", which is not a valid import path.
To resolve this issue, you should update the import statements in the index.js file to import ReactDOM from "react-dom" instead of "react-dom/client". Here is the corrected import statement: