4 ms·
That's not true. I've been fighting with React rerendering every element of a long list when I change one element and update the context state. For some reason
by bufferoverflow 7y ago
That's not true. I've been fighting with React rerendering every element of a long list when I change one element and update the context state. For some reason React rerenders everything, even when the keys are set and the references are the same.
The only recommendation I got is to use React.memo, which still rerenders every element, but from some internal cache.
- jbergens 7y agoI don't use context so I don't know if this is true or not. It might think it has to re-render since the context could affect anything below a component. It should however use the virtual DOM to diff first and not update the actual DOM more than needed. For class components in react you also have a special method shouldComponentUpdate that you can write to optimize things. But I feel we are into performance details now, it doesn't make the code hard to understand. You updated a value in the context and some component re-renderd, hopefully with the correct output.