I'm new to Redux, how would I reference the state of a nested array in my reducer?
Here is my state:
const initState = {
tabs: [
{ arr: [] },
{ arr: [] }
]
};
I tried doing something like:
tabs[0].arr: //do stuff
inside my reducer, but I get a parsing error. What is the correct way to reference the array in the first tab?
Edit: I am adding more code for clarity
function reducer(state = initState, action) {
if (action.type == 'ADD_ARR') {
return {
state.tabs[0].arr: [...state.tabs[0].arr, action.arr]
}
}
}
//I get this message: 'Parsing error: Unexpected token, expected ","' at the period between 'state' and 'tabs[0]'
The rest of my code
const arrAction = { type: "ADD_ARR", arr: "hello" };
store.dispatch(arrAction);