DEV Community

Discussion on: How to write performant React apps with Context

Collapse
 
kangweichan profile image
Kang-Wei Chan • Edited

Hi Nadia, fantastic article.

I had one question regarding the section of the article where you introduced the reducer pattern in order to avoid having to use state in the dependencies list of the useMemo. Is there any reason using useReducer as you have would be preferable to simply using setState(prevState => ...)?

Collapse
 
adevnadia profile image
Nadia Makarevich

Ha, perfect catch @kangweichan! Just haven't though about it 😳 It will also likely work for this scenario.

I just usually use reducers when the state becomes a bit big.

Collapse
 
lgibso34 profile image
Logan Gibson

I came here to ask the same thing. It does work!

Awesome article, Nadia!