SortableJS / react-sortablejs

React bindings for SortableJS
http://sortablejs.github.io/react-sortablejs/
MIT License
2.05k stars 210 forks source link

ReactSortable options not updating on rerender #185

Open IlyasArinov opened 4 years ago

IlyasArinov commented 4 years ago

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

mehdi-dalil commented 4 years ago

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

IlyasArinov commented 4 years ago

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

itsmichaeldiego commented 3 years ago

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!