↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

React Component Mental Models

The article explains two ways of thinking about React components. The older model separates container components, which handle state and data fetching, from presentational components, which handle how data is displayed. It then argues that hooks make this split less useful in modern UI applications because state and business logic can live closer to the components that use them.

Reading notes
#

  • Container components handle state and data fetching, while presentational components focus on how data looks to the user.
  • The article says this pattern can become hard to manage, extend, and test as applications grow.
  • Hooks let developers add statefulness without wrapping components in a container just to provide state.
  • A custom hook such as useUsers can hold business and application logic while UserList stays focused on display.
  • The Stateful and Stateless model spreads responsibility through the application instead of concentrating complexity in a few components.
  • The state and business logic should live as close as possible to where they are used.
  • In the form example, the Form component keeps business logic, while the Input component stays stateless and only shows validation errors.
  • Even a ToggleButton fits better in the Stateful and Stateless model because its active or inactive state lives inside the component.
  • The article recommends preferring the Stateful and Stateless components model for code that is easier to manage, extend, maintain, and test.