Skip to content

Commit

Permalink
fix: prevent calling setState in TransitionGroup if it has been unmou…
Browse files Browse the repository at this point in the history
…nted (#435)
  • Loading branch information
restlessbit authored and jquense committed Dec 10, 2018
1 parent c1787ed commit 6d46b69
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/TransitionGroup.js
Expand Up @@ -104,6 +104,11 @@ class TransitionGroup extends React.Component {

componentDidMount() {
this.appeared = true
this.mounted = true
}

componentWillUnmount() {
this.mounted = false
}

static getDerivedStateFromProps(
Expand All @@ -127,12 +132,14 @@ class TransitionGroup extends React.Component {
child.props.onExited(node)
}

this.setState(state => {
let children = { ...state.children }
if (this.mounted) {
this.setState(state => {
let children = { ...state.children }

delete children[child.key]
return { children }
})
delete children[child.key]
return { children }
})
}
}

render() {
Expand Down

0 comments on commit 6d46b69

Please sign in to comment.