Amy Blankenship
Sep 25, 2022

--

If you're having problems with your components' not rerendering when you expect them to (which seem really strange in the world of hooks, where you have to spend lots of effort preventing extra renders), it is highly likely that you're mutating the state instead of creating a new object. Since React does shallow equality checks (checks by reference rather than comparing the old version to the new version), if you mutate the state, it doesn't see that it has changed and won't rerender. It's a serious code smell to use key to force rerendering.

--

--

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)