reactjs hook useeffect code example
Example 1: react useeffect
import React, { useEffect } from 'react';
const [data,setData]=useState()
useEffect(() => {
fetch(`put your url/api request in here`)
.then(res=>res.json())
.then(json => setData(json))
},[])
Example 2: reacthooks
function Counter({initialCount}) {
const [count, setCount] = useState(initialCount);
return (
<>
Count: {count}
<button onClick={() => setCount(initialCount)}>Reset</button>
<button onClick={() => setCount(prevCount => prevCount - 1)}>-</button>
<button onClick={() => setCount(prevCount => prevCount + 1)}>+</button>
</>
);
}