Code React Sweetly
/
Effect Hooks
Effect Hooks
https://leanpub.com/code-react-sweetly
Types of Effects in React
https://leanpub.com/code-react-sweetly
How to Know the Effects That Require Cleanup
https://leanpub.com/code-react-sweetly
How to Know the Effects That Do Not Require Any Cleanup
https://leanpub.com/code-react-sweetly
How to Clean Up a Component’s Effects
https://leanpub.com/code-react-sweetly
When does React run the cleanup function?
https://leanpub.com/code-react-sweetly
Effect’s setup code vs Effect’s cleanup function
https://leanpub.com/code-react-sweetly
How to Specify When React Effects Should Run
https://leanpub.com/code-react-sweetly
Syntax of the Effect Hook
https://leanpub.com/code-react-sweetly
What is a reactive value in React?
https://leanpub.com/code-react-sweetly
Why are props reactive values in React?
https://leanpub.com/code-react-sweetly
Are all functions and variables reactive values?
https://leanpub.com/code-react-sweetly
Should functions or objects be in a dependency array?
https://leanpub.com/code-react-sweetly
Is the object returned by
useRef
a reactive value?
https://leanpub.com/code-react-sweetly
Is the
useRef().current
property a reactive value?
https://leanpub.com/code-react-sweetly
When does React run an Effect?
https://leanpub.com/code-react-sweetly
How to run Effects after every render
https://leanpub.com/code-react-sweetly
How to run Effects only after a function component’s first render
https://leanpub.com/code-react-sweetly
How to run an Effect after the first render, and when any of its dependencies change
https://leanpub.com/code-react-sweetly
What to know about the dependency array
https://leanpub.com/code-react-sweetly
Important Things to Know About the Effect Hook in React
https://leanpub.com/code-react-sweetly
Effects are best used to synchronize components with external systems.
https://leanpub.com/code-react-sweetly
Avoid unnecessary object and function dependencies by restructuring your Effect
https://leanpub.com/code-react-sweetly
Why does the dependency array view functions and objects declared in a component’s body as changed items on every render?
https://leanpub.com/code-react-sweetly
Static objects and functions are often best declared outside the component
https://leanpub.com/code-react-sweetly
Consider declaring dynamic objects and functions inside your Effect Hook
https://leanpub.com/code-react-sweetly
Depend on the primitive values an Effect actually needs instead of an entire object
https://leanpub.com/code-react-sweetly
React runs an extra setup → cleanup → setup cycle in development with strict mode
https://leanpub.com/code-react-sweetly
Previous
Variables vs. Refs vs. State
Up next
Forms in React
In this chapter
Effect Hooks
Types of Effects in React
How to Know the Effects That Require Cleanup
How to Know the Effects That Do Not Require Any Cleanup
How to Clean Up a Component’s Effects
How to Specify When React Effects Should Run
Important Things to Know About the Effect Hook in React