I need a little help with updating an inner element of an object using Object.assign in my redux reducer.
To better explain the scenario, I'm using NBA teams. I have an NBA object in my redux store. I'm now trying to update only the teamMembers for a particular team. My NBA object looks like this:
{
teams: [
{
teamId: 123,
teamName: "Los Angeles Lakers"
teamMembers: [
{id: "kbryant", fullName: "Kobe Bryant"},
{id: "bingram", fullName: "Brandon Ingram"}
]
},
{
teamId: 234,
teamName: "Miami Heat"
teamMembers: [
{id: "cbosh", fullName: "Chris Bosh"},
{id: "tjohnson", fullName: "Tyler Johnson"}
]
}
]
}
I pass both teamId and members to the reducer through my action i.e. action.teamId and action.members.
This is what I have so far:
Object.assign({}, state, {
nba: Object.assign({}, state.nba, {
teams: Object.assign({}, state.nba.teams, {
teamId[action.teamId] // I'm stuck here...
})
})
})
How do I update the teamMembers of a particular team? I know I'm almost there but could use a little help. Thanks.