react-sortablejs icon indicating copy to clipboard operation
react-sortablejs copied to clipboard

ReactSortable options not updating on rerender

Open IlyasArinov opened this issue 3 years ago • 3 comments

Hi! For some reason whenever I pass dynamic props that depend on state to ReactSortable component, the component options do not update.

Please check the sandbox: https://codesandbox.io/s/sortable-js-bug-4gpsd

As you can see initially ReactSortable gets passed IsDisabled = false, and then on first render it updates to true, but you can still sort.

Expected behavior For options to update according to props.

Versions: react-sortablejs = 6.0.0 react = 16.13.1

Please check the sandbox

https://codesandbox.io/s/sortable-js-bug-4gpsd

IlyasArinov avatar Sep 28 '20 15:09 IlyasArinov

It seems like its an issue with sortablejs, the options we give to the object at initialization are not being updated dynamically

mehdi-dalil avatar Oct 05 '20 08:10 mehdi-dalil

For whoever stumbles upon this, here is the solution: const key = useMemo(() => some uuid generator, [some props]); <ReactSortable key={key} ....

IlyasArinov avatar Oct 05 '20 14:10 IlyasArinov

I am having the same issue, the fix provided by @IlyasArinov works, but there should be a better way or a proper fix for this!

itsmichaeldiego avatar Jul 21 '21 03:07 itsmichaeldiego