Skip to content

Conversation

kernel-sanders
Copy link

Closes #99

@jcurtis
Copy link
Contributor

jcurtis commented Apr 2, 2018

Are you not able to use onChangeOrder and keep the order in state?

@jcurtis
Copy link
Contributor

jcurtis commented Apr 2, 2018

Ah I see you're having issue with performance using the state. If you need to keep the order but your render doesn't actually depend on it, you can keep in an instance variable instead. That way your component won't be forced to re-render.

class Foo extends React.Component { order = []; render() { return <SortableList onChangeOrder={newOrder => this.order = newOrder} /> } } 
@jcurtis
Copy link
Contributor

jcurtis commented Apr 2, 2018

The React docs explain why it's not a good idea to use refs for this type of logic https://reactjs.org/docs/refs-and-the-dom.html

@kernel-sanders
Copy link
Author

Using an instance variable accomplishes my needs without hurting performance and without using a ref! Thanks for the education!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants