--

Context may not be the best solution for performance, because each context can only contain one value. Often this value is implemented as an object with one property that's "the value" and another property that's a callback that lets you set it. The issue is that whenever either of these changes, everything that references the context will redraw. Libraries like Redux have done a lot of work to make sure that your actions have stable identities and values are referenced via memoized selectors.

Also context is pretty much unusable in Next 13 (which means if you plan to have a project in it you should also get out of the habit of using styled components now. It's not clear if state management libraries will be able to find a workaround.

--

--

Amy Blankenship
Amy Blankenship

Written by Amy Blankenship

Full Stack developer at fintech company. I mainly write about React, Javascript, Typescript, and testing.

Responses (1)