I'm using react-sortable-hoc to reorder table rows with Save and Cancel buttons. However, I can't find any information or example about reverting back to original order when the Cancel button is clicked after re-ordered rows.
Can't find any info or example on the official documentation or anywhere else. It seems weird to me that there's no cancel function built in or am I missing something?
Edit: Example code
If you want to undo order changes then you can maintain an undo stack. Each time an order change is complete, stash a copy of the previous
datastate. When the undo button is clicked you pop from the undo stack back into thedatastate.Add an
undoStackto state.Cache the previous
datastate in the undo stack. Here I'm using slice to keep only the last 10 revisions, but this can be tuned to fit your needs.Handle undoing order changes and attach the undo handler to the button's
onClickevent handler.Demo
If you don't care about intermediate revisions and simply want to reset to the original order then just capture a cache of the original order and reset
data.Both are implemented in the linked codesandbox.