React + Redux + Sortable problem
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?
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.
Wpould it be possible if I use react-dnd for sorting/draging elements?
It should be, here is a nice example: https://gaearon.github.io/react-dnd/examples-sortable-simple.html