react hooks setstate inside useeffect code example
Example 1: react useeffect on change props
useEffect(() => console.log('value changed!'), [props.isOpen]);
Example 2: useeffect cleanup function
function App() {
const [shouldRender, setShouldRender] = useState(true);
useEffect(() => {
setTimeout(() => {
setShouldRender(false);
}, 5000);
}, []);
// don't render
if( !shouldRender ) return null;
// JSX, if the shouldRender is true
return <ForExample />;
}