Skip to content

React Hooks and Effects

Hooks let function components manage state and lifecycle behavior without class components.

  • useState for local state
  • useEffect for synchronization with external systems
  • useReducer for more structured state transitions
  • useContext for shared values across a component tree

Effects are for work that reaches outside React’s render process, such as:

  • fetching data
  • subscribing to browser or network events
  • updating external libraries

They are not the right place for every piece of computed logic. If something can be derived during render, keep it in render.

Use hooks to make stateful behavior explicit. Use effects narrowly, with clear dependencies and cleanup behavior.