-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Newly rendered DOM elements not sortable #6
Comments
How about calling this.setState within componentWillReceiveProps? @Sortable(options)
class SortableList extends React.Component {
state = {
items: this.props.items
};
componentWillReceiveProps(nextProps) {
this.setState({ items: nextProps.items });
}
render() {
: : :
}
} |
@cheton that works if the render function always returns a list. However, in the event that the list of items is empty, in my use case, i am returning a message that says "This list has no items", and the render function never gets to the portion where a list is rendered. Perhaps this is a design flaw on my end by not extracting the sortable portion into it's own component? Flipping back and forth between lists that have no items and lists that have some items results in sortable not working render() {
const { items } = this.state
if (!items || !items.length) {
return <p>There are no items in this category.</p>
}
return (
<div>
<ul ref="list" >
{items.map((i, k) =>
<li key={k} >
....
) |
I just realised what you have encountered. I will take a look at your PR and merge it soon. Thanks! |
When new items are added or a set of items is replaced via new props, those new items/replaced items have not had Sortable.create called on them, and therefore their DOM elements are not sortable.
This is due to having the Sortable.create call only in componentDidMount but not also in componentDidUpdate
The text was updated successfully, but these errors were encountered: