Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent calling setState in TransitionGroup if it has been unmounted #435

Merged
merged 1 commit into from Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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