Normalizr + Redux - updating the property of one object
I am creating a music player application and I am using REST API to fetch tracks from different endpoints (playlists, tracks posted by a specific user, etc.).
I am using redux and normalizr to manage my state. I have created an object tracks
that I use to display the object track
and their ids.
In short, my state looks something like this:
{
playlists: {
123: { id: 123, name: 'foo', tracks: [1, 2, 3] }
},
users: {
me: { name: 'Niek', tracks: [2, 3] },
},
entities: {
tracks: {
1: { name: 'bar', user_favorited: false, ... },
2: { name: 'foo', user_favorited: false, ... },
3: { name: 'bar', user_favorited: true, ... }
}
}
}
This works great for me so far. But now I am creating functionality to toggle favorite
track state by calling another API endpoint.
This endpoint does not include the entire resource track
in the response, but I want to update the property of user_favorited
one object track
after a successful API call.
What would be the best way to achieve this?
As a workaround, I am now getting the complete object track
again from a different endpoint after the call to the endpoint completes successfully user_favorited
, but I was hoping to find an elegant solution where this is not needed.
source to share
No one has answered this question yet
Check out similar questions: