Skip to content

Commit

Permalink
fix: Prevent component from being updated after it gets unmounted (#49)
Browse files Browse the repository at this point in the history
Prevents container dimensions from being updated after it gets unmounted

Fixes #48
  • Loading branch information
cecigarcia authored and okonet committed Jun 15, 2018
1 parent 649ca20 commit ff18f61
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ export default class ContainerDimensions extends Component {
callOnAdd: false
})
this.elementResizeDetector.listenTo(this.parentNode, this.onResize)
this.componentIsMounted = true
this.onResize()
}

componentWillUnmount() {
this.componentIsMounted = false
this.elementResizeDetector.uninstall(this.parentNode)
}

onResize() {
const clientRect = ContainerDimensions.getDomNodeDimensions(this.parentNode)
this.setState({
initiated: true,
...clientRect
})
if (this.componentIsMounted) {
this.setState({
initiated: true,
...clientRect
})
}
}

render() {
Expand Down

0 comments on commit ff18f61

Please sign in to comment.