I have an array of users in my store set up like this:
{users: {user_id: 1, user_name: Adam, user_score: 100},
{user_id: 2, user_name: Bob, user_score: 200},
{user_id: 3, user_name: Charlie, user_score: 300}}
My project is receiving JSON data from the server that is set up like this:
{user_id: 1, score: 10}
I want to find where the user_id
of the passed data matches the existing user set's user_id
and update the score to the score
that was passed in.
For example, if the reducer receives {user_id:2, score:10}
how do I change the score
to 10
where the user id equals 2
in the original state. While avoiding mutation, of course!
What would be the best way to use do this? Normalizr? Lodash? update()? Seems pretty simple, I must be missing something obvious here. Thanks.