I would like to know, how can I move an object in array with Redux.
In my reducer I have this :
case SEQUENCES.MOVE_REPLY_ON_BLOCK :
indexBucket = action.indexBucket; // => 0
indexBlock = action.indexBlock; // => 0
indexReply = action.indexReply; // => 1
replySelected = action.payload.reply; // => my reply object
newIndex = action.payload.newIndex; // => 2
return {
...state,
buckets: state.buckets.map((bucket, i) => i === indexBucket ? {
...bucket,
blocks: bucket.blocks.map((block, i) => i === indexBlock ? {
...block,
messages: block.messages.map((message, i) => i === 0 ? {
...message,
replies: [
...state.buckets[indexBucket].blocks[indexBlock].messages[0].replies.splice(indexReply, 1),
...state.buckets[indexBucket].blocks[indexBlock].messages[0].replies.splice(newIndex, 0, replySelected)
]
} : message)
} : block)
} : bucket)
};
My tree looks like that:
buckets[
blocks[
messages[
replies [
{my_object},
{my_object},
{my_object},
...
]
]
]
]
I would like move the reply object in replies array, but with my code, I have no error but all replies are remove...
indexReply
tonewIndex
? What isreplySelected
then?splice
since it modifies source array; useslice
instead