-
Notifications
You must be signed in to change notification settings - Fork 281
Closed
Description
Hi,
I think the following code here (in Resizable component) did not remove the event listener attached to the window, which has caused the GC not being able to clean up the data of Resizable and its children even if the components' React lifecycles have ended.
constructor(props) {
super(props);
this.state = { width: 0 };
}
componentDidMount() {
window.addEventListener("resize", () => this.handleResize());
this.handleResize();
}
componentWillUnmount() {
window.removeEventListener("resize", () => this.handleResize());
}
handleResize() {
if (this.container) {
this.setState({
width: this.container.offsetWidth
});
}
}
Suggested change:
constructor(props) {
super(props);
this.state = { width: 0 };
this.handleResize = this.handleResize.bind(this);
}
componentDidMount() {
window.addEventListener("resize", this.handleResize);
this.handleResize();
}
componentWillUnmount() {
window.removeEventListener("resize", this.handleResize);
}
handleResize() {
if (this.container) {
this.setState({
width: this.container.offsetWidth
});
}
}
The change has been tested on my project. Haven't done a thorough test though. Hopefully this is helpful.
Cheers.
sartaj10
Metadata
Metadata
Assignees
Labels
No labels