I have a store with office and inside i have the array people. So it look like this/l
const office = (state = INITIAL_OFFICE, action) => {
switch(action.type){
case 'ADD_OFFICE':
const office = action.item;
office.people = [];
return {
...state,
offices: [...state.offices, office],
}
case 'ADD_PEOPLE_TO_DEVICE':
const { office_id, id, name } = action.item
const offices = [...state.offices];
offices[office_id+1].people.push({ name })
return {
...state,
offices
}
default:
return state
}
}
I created api which return json witrh 3 field - office_id, id of person and name of person. I want to add all people to array inside suitable office object. At this moment it display only 1 person in the office (I have many-to-many relationship) and Firefox (Chrome not) display my an error
offices[(office_id + 1)] is undefined
If I update manually key of protocols, for example protocols[2], all elements display with suitable office. How can I add all people to suitable office?
question from:
https://stackoverflow.com/questions/65891948/store-array-inside-object 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…