Chen Chen
Chen Chen

Reputation: 3

How to set array in redux toolkit?

I dont know how to change Starter or any kind of key's value in the player? If the player is not a array i know how to do,but i have no idea about how to set array's value.(I guess this may use filter but i don't know actually how to do)

const playerSlice = createSlice({
    name: "player",
    initialState:{
        player:[
         {
           Name: 'cc',
           Starter:true,
           key:'1',
         },
        ]
   },
 
    reducers: {
        setPlayer:(state,action){
        //how to set Starter?
        }
    }

});

Upvotes: 0

Views: 354

Answers (1)

phry
phry

Reputation: 44086

If you want to set the starter-property of the first player in the array, you can access that at index 0.

state.player[0].Starter = false

Upvotes: 1

Related Questions