I m using node.js for this and using react as frontend, Now how do I import app.jsx file to index.js file? index.js
JavaScript
x
5
1
import App from "./components/app";
2
3
ReactDOM.render(<App text="Hello world"/> , document.getElementById('root'))
4
5
app.jsx
JavaScript
1
6
1
function App(props){
2
return <h1>{props.text}</h1>
3
}
4
5
export default App;
6
now at last in app.jsx file I tried to import/require the React file but I get an error “require is not defined”
also in console when importing app.jsx it says require is not defined i m using import and that’s what it says
Advertisement
Answer
use npx create-react-app
in your terminal to create new starter react app, you will see the working code over there.
link for more info https://create-react-app.dev/docs/getting-started