February 2022
Intermediate to advanced
254 pages
4h 13m
English
React has provided Context since version 16.3. Context has nothing to do with states, but it's a mechanism for passing data from component to component instead of using props. By combining Context with a component state, we can provide a global state.
In addition to the Context support provided since React 16.3, React 16.8 introduced the useContext hook. By using useContext and useState (or useReducer), we can create custom hooks for a global state.
Context is not fully designed for global states. One of the known limitations is that all Context consumers re-render upon updates, which can lead to extra re-renders. It's a general recommendation to split a global state into pieces.
In this chapter, ...
Read now
Unlock full access