Skip to content

Commit 4ebe677

Browse files
committed
fix(grid): let the thing update, do prop changes in the sane place
also destroy the grid on unmount to remove hanging refs
1 parent 87de2bf commit 4ebe677

File tree

3 files changed

+107
-35
lines changed

3 files changed

+107
-35
lines changed

package-lock.json

Lines changed: 89 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"dependencies": {
3838
"classnames": "^2.2.5",
39-
"grid": "^4.10.8",
39+
"grid": "~4.10.9",
4040
"lodash": "^4.17.4",
4141
"react": "^16.0.0",
4242
"react-dom": "^16.0.0"

src/lib/components/grid.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,6 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
130130
}
131131
}
132132

133-
shouldComponentUpdate(nextProps: IGridProps) {
134-
if (this.descriptorsChanged(this.props.rows, nextProps.rows)) {
135-
this.reflectNewRowsOrCols(nextProps.rows, this.grid.rows);
136-
}
137-
if (this.descriptorsChanged(this.props.cols, nextProps.cols)) {
138-
this.reflectNewRowsOrCols(nextProps.cols, this.grid.cols);
139-
}
140-
141-
if (this.props.data !== nextProps.data) {
142-
this.handleNewData(nextProps.data);
143-
}
144-
return false;
145-
}
146-
147133
componentDidMount() {
148134
this.ensureGridContainerInDOM();
149135
this.grid.build(this.gridContainer);
@@ -180,8 +166,24 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
180166
}
181167

182168
// we return false from should update but react may ignore our hint in the future
183-
componentDidUpdate() {
169+
componentDidUpdate(prevProps : IGridProps) {
184170
this.ensureGridContainerInDOM();
171+
172+
const nextProps = this.props;
173+
if (this.descriptorsChanged(prevProps.rows, nextProps.rows)) {
174+
this.reflectNewRowsOrCols(nextProps.rows, this.grid.rows);
175+
}
176+
if (this.descriptorsChanged(prevProps.cols, nextProps.cols)) {
177+
this.reflectNewRowsOrCols(nextProps.cols, this.grid.cols);
178+
}
179+
180+
if (prevProps.data !== nextProps.data) {
181+
this.handleNewData(nextProps.data);
182+
}
183+
}
184+
185+
componentWillUnmount(){
186+
this.grid.destroy();
185187
}
186188

187189
render() {

0 commit comments

Comments
 (0)