I have started my first React lesson but I cant see any output on my localhost(3000), will you pls help me ?
this is my JS code :
import React from 'react';
import ReactDOM from 'react';
const element = React.createElement("div", { id: "title", className: "app-title" }, "this is a test text");
ReactDOM.render(element, document.getElementById("root"));
CodePudding user response:
Look at the Console in your browser's developer tools. When I run this code it says:
Uncaught TypeError: _reactDefault.default.render is not a function
So something is wrong with the object you call render
on. That clues us into looking at the place it is defined.
import React from 'react'; import ReactDOM from 'react';
You've imported react
twice and assigned it to different variables. That doesn't make a whole lot of sense.
So go back and check the tutorial you are working from.
You should see that ReactDOM
should be imported from 'react-dom'
and not 'react'
.
import React from 'react';
import ReactDOM from 'react-dom';