ReactJs Components

Why hooks

  • why hooks
    • simplify code
      • previously for new comers to react, there was a need to learn what this means in javascript making the learning experience harder
    • make it more performant
  • useState
    • set as a prefix is a convention
  • useEffect
    • it is a side effect (pure vs impure functions)

rules

- call hooks only from react function
- call hooks at the top level
- you can call multiple state or effects
- make multiple calls in sequence - [fetch data](https://react.dev/reference/react/useEffect#fetching-data-with-effects)
- used to make server request - advanced hooks
- useReducer 
	- The useReducer hook is best used on more complex data, specifically, arrays or objects.
- useRef
- [custom hooks](https://react.dev/learn/reusing-logic-with-custom-hooks)

Examples

Resources