View on GitHub

reading-notes

Reading

Introducing Hooks

What was the motivation for introducing Hooks?

The motivation for introducing Hooks was to allow developers to use state and other React features in functional components, rather than just in class-based components.

What changes are important regarding implementing Hooks versus Component Classes?

When implementing Hooks, you can use functional components instead of class-based components, and you can manage state and side effects using Hooks instead of using the this keyword and lifecycle methods.

Hooks allow you to reuse stateful logic without changing **_ **_****.

the component hierarchy

hooks api

Name two rules imposed by React Hook usage.

Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions. Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions.

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

You can identify a custom Hook by the use prefix in the function name. You might create a custom Hook to share stateful logic that is useful in multiple components.

the state hook

What is a Hook?

A Hook is a function that lets you “hook into” React features from functional components.

When would I use the useState Hook?

You would use the useState Hook to add state to a function component.

If you were to add React state to a function component by declaring a state variable: