Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1.74 KB

File metadata and controls

27 lines (20 loc) · 1.74 KB

Context API

Review, Research, and Discussion

Describe use cases useState() vs useReducer()

  • useState() would be good to use on a component where you are only managing that specific state in that component and there aren't multiple states to manage.
  • useReducer() is good when there are multiple states being managed and used by multiple components as it ensures state doesn't transform in unexpected ways.

Why do custom hooks need the use prefix?

  • custom hooks should always start with use so that it is clear that the rules of Hooks apply to it and allows React to check for violations against those rules

What do custom hooks usually do?

  • custom hooks allow you to remove duplicated logic from two compoents that needs to change on the same state. They don't share state, but are a tool to reuse stateful logic.

Using any list of custom hooks, research and name one that you think will be useful in your applications

  • useToggle() - this custom hook would be useful anytime I need to incorporate or manipulate state that goes from true to false or false to true.

Describe how a hook that fetches API data might work

  • I would set it up so it takes in an axios request config object, then anytime I need to modify state based on an API request use the hook.

Vocab

reducer

  • reducers are the pure functions that take the current state and action and return the new state and tell the store how to do source

Resources