reading-notes

Reading: useState() Hook

Introducing Hooks

1. 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?

  1. Hooks allow you to reuse stateful logic without changing your component hierarchy.
  2. Hooks let you split one component into smaller functions based on what pieces are related (such as setting up a subscription or fetching data)
  3. Hooks let you use more of React’s features without classes

3. Hooks allow you to reuse stateful logic without changing _________ _________.

… without changing your component hierarchy.

hooks api

1. Name two rules imposed by React Hook usage.

  1. Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions.
  2. Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions. (There is just one other valid place to call Hooks — your own custom Hooks. We’ll learn about them in a moment.)

2. How would you identify a custom Hook and why might you create one?

The use keyword

the state hook

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:

Bookmark and Review

Things I Want To Know More About

Previous Reading

Next Reading