Reactreact-native

React useEffect Review

By Fangtai Dong
Picture of the author
Published on
react and react native bg

useEffect Summary

  1. useEffect( ()=>{console.log('Effect Running')} )
  • 1st moment and every state update will run it
  1. useEffect( ()=>{console.log('Effect Running')}, [])
  • only execute once for the 1st moment
  1. useEffect( ()=>{console.log('Effect Running')}, [enteredPassword])
  • 1st moment and every enteredPassword state update will run it
  1. 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.
  1. 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?

© 2023 Fangtai Dong. All rights reserved.