players, ifActive, tabs, , :
const initialPlayerState = {
tabs: [
{ id: 1, name: 'player 1', ifActive: false },
{ id: 2, name: 'player 2', ifActive: false },
{ id: 3, name: 'player 3', ifActive: false },
]
}
const playerReducer = (state = initialPlayerState , action) => {
switch (action.type) {
case SELECT_PLAYER:
return {
...state,
tabs: tabs.map(player => player.ifActive || player.id === action.id ? {
...player,
ifActive: player.id === action.id
} : player)
};
default:
return state;
}
}