- )
})
return (
{itemsarray}
);
}
ReactDOM.render( , document.getElementById("root"));
```

After deleting ‘strawberry’:

- render parent component when child state is changed.
Normally when parent component is re-rendered, child component also get rendered.
Proof:
```jsx
import React from 'https://cdn.skypack.dev/react';
import ReactDOM from 'https://cdn.skypack.dev/react-dom';
// import {useState} from 'https://cdn.skypack.dev/react'
const {useState} =React
const Child=(props)=>{
const [state,setState]=useState(0)
console.log('Child component rendered')
return(
Child
{
console.log('child button clicked')
setState(state+1)
}} className="">{state}
)
}
const App = () => {
const [state,setState]=useState(0)
console.log('\nParent component rendered')
return (
{
console.log('Parent button clicked')
setState(state+1)
}}>{state}
);
}
ReactDOM.render( , document.getElementById("root"));
```

To stop rerendering: use React.memo() while exporting child component in Child.js file
```jsx
import React from "react";
function Child(props) {
console.log("child component");
return child Page
;
}
export default React.memo(Child);
```
When child component is updated then parent component is not updated as we can see from console output.
So to update the parent component when child component is updated.
If we want to rerender parent component for any child state changes then we can pass any state like render and setRender from parent to child and change that state in child component when child state changes thus updating parent component too.
```jsx
const Child=({setRender,render})=>{
const [state,setState]=useState(0)
useEffect(() => {
setRender(render+1)
}, [state])
console.log('Child component rendered')
return(
Child
{
console.log('child button clicked')
setState(state+1)
}} className="">{state}
)
}
const App = () => {
const [state,setState]=useState(0)
const [render,setRender]=useState(0)
console.log('\nParent component rendered')
return (
{
console.log('Parent button clicked')
setState(state+1)
}}>{state}
);
}
ReactDOM.render( , document.getElementById("root"));
```

- Animation
Tilt and Particles:

For GUI testing in particles.js use:
[https://vincentgarreau.com/particles.js/](https://vincentgarreau.com/particles.js/)
- tippyjs


- Equivalent of useEffect
For eg: using useeffect:
```jsx
import { useState, useEffect, Fragment } from "react";
import "./styles.css";
export default function App() {
const [int, setInt] = useState(0);
useEffect(()=>{
console.log(int)
},[int])
const handleClick=()=>{
setInt(int+1)
}
return (
Hello CodeSandbox
Start editing to see some magic happen!
);
}
```
same using componentDidUpdate()
```jsx
import "./styles.css";
import {Component} from 'react'
class App extends Component
{
constructor(){
super()
this.state={
int: 0
}
// this.handleClick=this.handleClick.bind(this)
}
handleClick=()=>{
this.setState({int: this.state.int+1})
// console.log(this.state.int)
}
componentDidMount(){
console.log(this.state.int)
}
// for checking props, prevProps is used instead of prevState
componentDidUpdate(prevState){
if(this.state.int!==prevState.int){
console.log(this.state.int)
}
}
render(){
return(
Hello CodeSandbox
Start editing to see some magic happen!
)
}
}
export default App;
```
- bind() method
[https://www.freecodecamp.org/news/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb/](https://www.freecodecamp.org/news/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb/)
By default user defined methods in class components is not binded by default so we need to explicitly bind it.
```jsx
class Foo extends React.Component{
constructor( props ){
super( props );
this.handleClick = this.handleClick.bind(this);
}
handleClick(event){
// your event handling logic
}
render(){
return (
Click Me
);
}
}
ReactDOM.render(
,
document.getElementById("app")
);
```
if bind is not used then this.handleclick wont be available.
- dispatch
[dispatch() is the method used to dispatch actions](https://redux.js.org/api/store#dispatchaction)
and trigger state changes to the store. react-redux is simply trying to give you convenient access to it
- Lifescycle of useeffect,usestate and useref
First if any even changes state then state is changed causing component to re render so that new state value if used in DOM will be updated too
Then after component is re render, side effects in useEffect take place if specified state in array(2nd parameter changes)
Example to demonstrate:
```jsx
import { useState, useEffect, useRef } from "react";
import ReactDOM from "react-dom/client";
function App() {
const [inputValue, setInputValue] = useState("");
const previousInputValue = useRef("");
useEffect(() => {
previousInputValue.current = inputValue;
}, [inputValue]);
return (
<>
setInputValue(e.target.value)}
/>
Current Value: {inputValue}
Previous Value: {previousInputValue.current}
>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render( );
/*
Start typing in the input field and you will
see the current- and previous value.
*/
```

- Alternative of innerHTML in react
[https://stackoverflow.com/questions/19266197/reactjs-convert-html-string-to-jsx](https://stackoverflow.com/questions/19266197/reactjs-convert-html-string-to-jsx)
```jsx
import ReactHtmlParser from 'react-html-parser'
{ReactHtmlParser(htmlString)}
```
- Preventing propagation of event from parent to child
[https://www.antimath.info/jquery/prevent-inner-elements-trigger-an-event-on-the-parent/](https://www.antimath.info/jquery/prevent-inner-elements-trigger-an-event-on-the-parent/)
```jsx
$('#parent a').on('click', function(event){
//stop the event bubbling up to the parent
event.stopPropagation();
});
$('#parent').on('click', function(event){
//attach event on the parent
alert('Parent element clicked!');
});
```
- Disabling eslint for specific piece of code
```jsx
searchednotes.push(note);
}
setIsSearching(true);
setSearchedNotes(searchednotes);
}, [searchValue]); // eslint-disable-line react-hooks/exhaustive-deps
```
- React helmet
- Creating and export/import text file in react
```jsx
const download=()=>{
fetch(`${HOST}`,{
})
.then(res=>res.blob())
.then(blob=>{
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = "extraordinary12.mp3";
link.href = url;
link.click();
})
.catch(console.log)
}
```
[https://spin.atomicobject.com/2022/03/09/create-export-react-frontend/](https://spin.atomicobject.com/2022/03/09/create-export-react-frontend/)
[https://spin.atomicobject.com/2022/03/09/create-export-react-frontend/](https://spin.atomicobject.com/2022/03/09/create-export-react-frontend/)
[https://www.geeksforgeeks.org/how-to-read-a-local-text-file-using-javascript/](https://www.geeksforgeeks.org/how-to-read-a-local-text-file-using-javascript/)
```html
Read Text File
```
- Common mistakes
[https://www.youtube.com/watch?v=Fhu5cu864ag](https://www.youtube.com/watch?v=Fhu5cu864ag)
[https://www.youtube.com/watch?v=Fhu5cu864ag](https://www.youtube.com/watch?v=Fhu5cu864ag)
- image to dataURI
[Extract data uri from image](../../Export-9fad9947-5bd5-4195-952b-6512c5a4beb1/Web%20development%2083dd4e6675f04ba782a6865a434a0598/React%205b9af27e2c194a4cb22a32306e53c39f/Extract%20data%20uri%20from%20image%205610c5f6df1b49978b3a19.md)
- Nodejs 17+ changes
We need to add this in scripts section in package.json file:
```json
"start": "react-scripts --openssl-legacy-provider start",
"build": "react-scripts --openssl-legacy-provider build",
```
the `--openssl-legacy-provider` flag is added as extra
- JoTai global state
Instead of using useState and passing it in prop repeatedly, we can use it globally by calling the state from a file.
atom.js
```jsx
import { atom } from 'jotai'
export const countAtom = atom(0)
```
App.js
```jsx
import { useAtom } from 'jotai'
import {countAtom} from './atom'
function Counter() {
const [count, setCount] = useAtom(countAtom)
return (
{count}
setCount((c) => c + 1)}>one up
...
```