This is my code:
Why is this not working?
The code is suppose to show the h1 in the html file, but for some reason it doesn't do that for me.
Element.js :
import React from "react"
function Element() {
return (
<div>
<h1>Hello World</h1>
</div>
)
}
export default Element
app.js :
import React from 'react'
import ReactDOM from 'react-dom'
import Element from './Element.js'
ReactDOM.render(<Element />, document.getElementById('root'))
the html code:
<script src="/index.js" type="text/babel"></script>
<div id="root"></div>
I looked at many solutions at stackoverflow but this bug it still doesn't work. I added import React from "react" and import ReactDOM from "react-dom" in both files but still same thing: nothing in the return statement doesn't show up, I've been struggling for hours. What is wrong with my code?
import/exportproblem. You have<script src="/index.js" type="text/babel"></script>. That would mean that your code was being handled by the client-side Babel Standalone (not recommended where it can be avoided). I suspect you meant for your code to be transpiled during a build process. You'll have to configure that for it to happen (or start with a scaffolding tool like create-react-app).