useState()
Hook1. What was the motivation for introducing Hooks?
To facilitate the reuse of stateful logic, the easier atomization of components, and more easily allowing the use of functional components, whilst retaining the React’s core features.
2. What changes are important regarding implementing Hooks versus Component Classes?
3. Hooks allow you to reuse stateful logic without changing _________ _________.
… without changing your component hierarchy.
1. Name two rules imposed by React Hook usage.
2. How would you identify a custom Hook and why might you create one?
The use
keyword
1. What is a Hook?
A hook is a React feature that lets us use React features without writing a class.
2. When would I use the useState
Hook?
You’d use useState
to add React state to a functional component.
3. If you were to add React state to a function component by declaring a state variable:
What does calling useState
do?
It declares a state variable
, so we can preserve
values between function calls.
useState
as an argument?
useState
.useState
return?
useState
returns a pair of values: the current state and the function that updates state.