In this post, I would like to share a brief history of ReactJS and its solutions to state management. You may probably know these already, but I think it would give a glimpse of how React evolves all the way long for those who are new to this framework, or a quick refresh if you are a veteran.

Two Camps of Components

React has two types of components — Class-based and Functional. As the names suggest, class components inherit React.Component and implement methods such as constructor and render for React to invoke, while function components are literally “functions” that take some inputs “props” and return the component to be rendered.

Prior to React v16.8, only class components can maintain a state and expose a handler to update the state. What’s more, there is a full set of methods to perform state management, side effects, and calculations at different time points throughout the component lifecycle. Class components can do everything you need to render a single-page application, even with performance optimization with thePureComponent, and it is the only way to do these jobs.

Function components, on the other hand, are pure functions that cannot have state and side-effects, but just rendering. One may call them “dumb components”, in contract to “smart components” that can contain much more business logic, side-effects, state manipulation, and controls on child components.

#state-management #react #react-hook

React Hooks and the Evolution of State Management
2.05 GEEK