.js in React files have the following format
- IMPORTS This is where you put stuff you are importing.
import React from 'react';
import {createRoot} from 'react-dom/client';
***note for mobile, it is react-native
react-dom is for the web
- The Element
How to create a react element
cont elementName = React.createElement(
)
- EXPORTS const contaier = document.querySelector('#root') **This is basically the instruction telling it where to go. *the page(s) where you want to put this element say this is where they go by your putting #root in. const root = createRoot(container); **you have to create the container that the element will go in. root.render(element);
Top comments (1)
Components are usually defined as JS functions and will return one or more React elements.
React elements describe what we want to create.
React.createElement('html thing like h1 or p or div', ,
what goes in the html
)React.createElement(FunctionName, null)
**You have got to capitalize the function name, this is what lets react know you want it to be processed as a component