I have an array I'm writing a code for redux now.
const initialState = [{ id: '1', title: '', description: '' }];
I would like to update that array like this
[{ id: '1', title: '', description: '' },{ id: '2', title: '', description: '' }];
and after copying I want to update the copy one of id to '2'
here is what I tried
case COPY_QUESTION: {
const copyQuestion = state.find(question => question.id === action.payload)
copyQuestion?.id = (state.length + 1).toString()
return [...state, copyQuestion];
}
it didn't work for me. if I try to change id, the 0 index changes too at the same time. like this
[{ id: '2', title: '', description: '' },{ id: '2', title: '', description: '' }];
I would really appreciate your help thanks for reading this question.