References: velopert
- The most basic
Hookthat allows functional components to hold mutable state - When you need to manage state in a functional component, use
Hooks!
- A
Hookthat allows you to set up specific tasks to be performed each time a React component renders - Think of it as a combination of
componentDidMountandcomponentDidUpdatefrom class components! - Executed right after each render
- The execution conditions differ depending on what you put in the second parameter array
-
When you want it to run only on the first render, and not when updated,
-
Pass an empty array (
[]) as the second parameterex)
useEffect( ()=> { console.log('This runs only when mounted!') }, [])
-
ex)
useEffect( () => {
console.log('This will run when age changes on New Year!')
}, [age])