Skip to content
Advertisement

How to update single value inside specific array item in redux

I have an issue where re-rendering of state causes ui issues and was suggested to only update specific value inside my reducer to reduce amount of re-rendering on a page.

this is example of my state

JavaScript

and I am currently updating it like this

JavaScript

where action.payload is a whole array containing new values. But now I actually just need to update text of second item in contents array, and something like this doesn’t work

JavaScript

where action.payload is now a text I need for update.

Advertisement

Answer

You could use the React Immutability helpers

JavaScript

Although I would imagine you’d probably be doing something more like this?

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement