I have installed React.js using the following command:
create-react-app my-app
npm start
http://localhost:3000/
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
Why did you do ??
</p>
</div>
);
}
}
export default App;
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
export default App;
Failed to compile
./src/App.js
Line 5: 'ReactDOM' is not defined no-undef
Line 10: 'App' is not defined no-undef
Search for the keywords to learn more about each error.
The errors are pretty self-explanatory:
Line 5: 'ReactDOM' is not defined no-undef
You are using ReactDOM.render
, but you're not importing it, so it's not defined.
Also, you probably don't want to use it at all, because it's already being called in another file (src/index.js
).
Line 10: 'App' is not defined no-undef
The original code declared a class App
and exported it. You removed the class declaration, but you kept the export, which references the now non-existent class App
.