- 2
In react basically i want to understand this explain me
import React from 'react'; import ReactDOM from 'react-dom/client'; const myFirstElement = <h1>Hello React!</h1> const root = ReactDOM.createRoot(document.getElementById('root')); root.render(myFirstElement); /* You are now watching the React file 'index.js' through our 'Show React' tool. */
1 Resposta
0
import React from 'react';
It is a react libary file. Basically a class file that has many useful functions (hooks) like useState(), useEffect(), useRef(), useReducer() ect.
import ReactDOM from 'react-dom/client';
It is also a react library file, used to create virtual dom elements using jsx. It provides functions like createRoot(), render() etc.
const root = ReactDOM.createRoot() -> used to create a root element. All your components gets rendered inside this root.
const myFirstElement = <h1> Hello React </h1> -> a variable that holding a h1 element. It is a jsx syntax
root.render() -> whatever provided inside as the argument will get rendered/display in the webpage under the root element.