Reactreact-native
React useEffect Review
By Fangtai Dong
- Published on
Sharing
useEffect Summary
useEffect( ()=>{console.log('Effect Running')} )
- 1st moment and every state update will run it
useEffect( ()=>{console.log('Effect Running')}, [])
- only execute once for the 1st moment
useEffect( ()=>{console.log('Effect Running')}, [enteredPassword])
- 1st moment and every enteredPassword state update will run it
useEffect( ()=>{console.log('Effect Running') return ()=>{console.log('Clean Up')} }, [enteredPassword])
- Clean up function will run every 2nd time component re-executed based on the enteredPassword state change. And this clean up function will run before the effect function run.
useEffect( ()=>{console.log('Effect Running') return ()=>{console.log('Clean Up')} }, [])
- Clean up function will run when the component is removed.
Hi there! Want to support my work?