The problem with context is simple: Everything that consumes a context re-renders everytime that context’s state changes.
That means that if you’re consuming your context all over the place in your app, or worse, using one context for your entire app’s state, you’re causing a ton of re-renders all over the place!
function App() {
return (
<div>
<h2>No Unnecessary Re-renders! 😎</h2>
<MessageProvider>
<Message />
<Message />
<Message />
</MessageProvider>
<CountProvider>
<Count />
</CountProvider>
</div>
)
}
render(App)
Comments
Post a Comment