.setState() Not Working? Shallow Copy vs Deep Copy & Lodash

James Dorr
JavaScript in Plain English
4 min readSep 10, 2019

--

There are times in React and Redux when you are trying to update the state and it just doesn’t work. Maybe it has already been working in other cases. You start to question your sanity as you go through […theSpreadOperator], Object.assign(), and any other copying methods you can find on the internet. Unfortunately, the issue isn’t your copying method, it’s your copying type — you likely need a deep copy instead of a shallow copy.

Examples here are specific to React and Redux, but understanding shallow and deep copies is valuable…

--

--

Full Stack Web Developer, former English as a foreign language teacher and volleyball coach. All views and opinions are my own.