React JS
Content from : LinkedIn
This was created by Facebook(now Meta).
ReactJS has a developer tool, which allows easy debugging and development.
Creating a project :
bash
npx create-react-app react_project_name
Here npx
is a package runner.
npm start
for starting the app.
React uses a syntax format called JSX, which is XML embeddings in JS.
It is able to do so through a tool called Babel.
Important
- React.render
- React.StrictMode
- React.creatElement(elementTag, cssProps, innerHtml)
Creating a component
Make a function that returns JSX.
You can pass props to a function, which can contain the data it needs to hold it.
js
function Comp(props){
console.log(props.yourKey);
}
It is better to have a list of elements as objects instead of strings or any other primitive :
jsx
const dishes = ["some1", "some2"];// throws error while rendering
const dishObjs = dishes.map((dish, i) => {id : i, dish : dish}); // do this
React.Fragment helps us to add a wrapper.
jsx
<React.Fragement>
</React.Fragement>
# or
<>
</>
# in essence
ReactDOM.render(
<>
<App />
<SomeOtherApp />
</>
,
document.getElementById('root')
);
This is useful as wrapping the content in <div>
adds extra nesting.
Important stuff :
- Conditional rendering
- Array destructuring
- useState Hook
- useEffect
- useReducer