I have the following case inside of my reducer. It is triggered when a user answers a question. When a user answers a question, it need to be removed from a nested array.
Example question object (these are in an array)
{
"title": "Quick Questions",
"questions": [
"title": "Hello?"
"answers" [ /*... array of answers in here */ ]
]
}
My reducer case
case ANSWER_QUESTION:
// The 0s here would be dynamically populated
state.questionGroups[0].questions.splice(0, 1)
return Object.assign({}, {
...state,
})
However, here I am directly manipulating the state, which I know is incorrect and will cause redux to not update the states correctly to get my components to rerender.
What is the correct way to do this?
EDIT: This may or may not be the reason my component isnt re-rendering. That might be to do with the fact that using connect()
only applies shallow comparisons, is that correct?