How can we ensure that an effect hook runs only once?
- the useEffect hook takes a second parameter which takes in an array of values. If you put certain props and state in that array, then the useEffect hook will only run when those specific items are updated, but if you put an empty array there, then the useEffect hook will only run once.
Can useState() update more than one state variable at the same time?
- if you set your state to an object you can update part or all of the variables in the object at once, but need to make sure all of the values are present otherwise they will get over written.
Is useState() synchronous?
- use state is asynchronus meaning that it does not update the state immediately.
State Hook
-
- A Hook is a special function that lets you “hook into” React features. For example, useState is a Hook that lets you add React state to function components. We’ll learn other Hooks later. source
Component Lifecycle
- The component lifecycle represents the various stages of a component as it is it called, rendered on a page (mounted), updated, or removed from a page (unmounted).