Skip to content

Commit 64bc7cb

Browse files
committed
Reinitialize sortable on componentDidUpdate
1 parent 373e67f commit 64bc7cb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/index.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ const SortableMixin = (options = defaultOptions) => (Component) => class extends
105105
}, 0);
106106
};
107107
});
108-
109-
const domNode = ReactDOM.findDOMNode(sortableComponent.refs[this.sortableOptions.ref] || sortableComponent);
110-
this.sortableInstance = Sortable.create(domNode, copyOptions);
108+
this.populatedOptions = copyOptions
109+
this.initSortable(sortableComponent);
111110
}
112111
componentWillReceiveProps(nextProps) {
113112
const sortableComponent = this.refs[refName];
@@ -120,12 +119,23 @@ const SortableMixin = (options = defaultOptions) => (Component) => class extends
120119
sortableComponent.setState(newState);
121120
}
122121
}
122+
componentDidUpdate() {
123+
this.initSortable(this.refs[refName]);
124+
}
123125
componentWillUnmount() {
124126
if (this.sortableInstance) {
125127
this.sortableInstance.destroy();
126128
this.sortableInstance = null;
127129
}
128130
}
131+
initSortable(sortableComponent) {
132+
if (this.sortableInstance) {
133+
this.sortableInstance.destroy();
134+
this.sortableInstance = null;
135+
}
136+
const domNode = ReactDOM.findDOMNode(sortableComponent.refs[this.sortableOptions.ref] || sortableComponent);
137+
this.sortableInstance = Sortable.create(domNode, this.populatedOptions);
138+
}
129139

130140
render() {
131141
return (

0 commit comments

Comments
 (0)