Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Last active November 26, 2018 09:05
Show Gist options
  • Save rcdexta/9274cb21fd16da39dbce49a7e7b2e992 to your computer and use it in GitHub Desktop.
Save rcdexta/9274cb21fd16da39dbce49a7e7b2e992 to your computer and use it in GitHub Desktop.
class ItemList extends React.Component {
state = {
items: this.props.items
};
onSortEnd = ({ oldIndex, newIndex }) => {
this.setState({
items: arrayMove(this.state.items, oldIndex, newIndex)
});
};
static getDerivedStateFromProps(props, state) {
if (props.items.length !== state.items.length) {
return {
items: props.items
};
}
return null;
}
render() {
return <SortableList items={this.state.items} onSortEnd={this.onSortEnd} />;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment