react icon indicating copy to clipboard operation
react copied to clipboard

React + Redux + Sortable problem

Open rhoman opened this issue 10 years ago • 3 comments

Hello,

I'm trying to sort list of elements (each with unique key) in aplication based on React and Redux. For sorting I'm using: https://github.com/RubaXa/Sortable and it works really good until I save my sort order to redux store. After my store changes it triggers re-rendering elements, which swap them back to previous positions, probalbly because React can'd detect that Sortable already made that change in DOM.

It all works well when I use Math.random for keys but I'd really like to avoid that.

Can I force React to detect that keys in displayed list already changed it's order?

rhoman avatar Jul 13 '16 07:07 rhoman

No, you can’t have both React and another library modify the same DOM element(s).

What you technically could do is just render a <div /> that never changes, and call your custom library from lifecycle hooks such as componentDidMount and componentWillReceiveProps. However in this case you would be sidestepping React completely.

gaearon avatar Jul 14 '16 12:07 gaearon

Wpould it be possible if I use react-dnd for sorting/draging elements?

rhoman avatar Jul 15 '16 05:07 rhoman

It should be, here is a nice example: https://gaearon.github.io/react-dnd/examples-sortable-simple.html

alexzherdev avatar Jul 15 '16 06:07 alexzherdev