2 ms·
The usual misunderstandings about context are: - Thinking that if you change a field in the context value only components that read that field will re-render
by acemarke 4y ago
The usual misunderstandings about context are:
- Thinking that if you change a field in the context value only components that read that field will re-render
- Thinking that _only_ the components that consume the context will re-render, not realizing that normal recursive rendering behavior resumes from there
- Not realizing that updating a context requires a `setState` call in the parent that renders the `<MyContext.Provider>`, and you can easily end up in a situation where the _entire_ component tree renders just because of default recursive rendering
Can you point to some examples of the "useless nesting" and "weird constructs" you're referring to? I'm curious to see what's happening, and if there's any docs improvements we can add to help provide guidance.
- mikojan 4y agoThese "misunderstandings about context" are not specific to context. React developers will have to learn about them whether they are using context or not. > Can you point to some examples of the "useless nesting" and "weird constructs" you're referring to? Example: Create a slice with a list of items as initial state and truncate it in a reducer.