import React, { component} from 'react';
class Hello extends component{
render(){
return <div>
<h1>Hello World</h1>
<p>Welcome to React</p>
</div>
}
}
export default Hello;
the code works but it doesnt return anything besides a blank page
——————————–this is from the index.js file
import React from 'react'; import ReactDOM from 'react-dom/client'; import './index.css'; import Hello from './Hello'; import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <React.StrictMode> <h1> Hello World</h1> <Hello/> </React.StrictMode> )
2
Answers
Should be
Component
instead ofcomponent
.And make sure your
index.js
same same like thisIncorrect Import of
Component
: You are importingcomponent
instead ofComponent
from React. This will cause your Hello component to not work as expected because it doesn’t extend the correct class.