From 6d46b691cd64b3912c016844ba706b38de77ced0 Mon Sep 17 00:00:00 2001 From: Mario Pabon Date: Mon, 10 Dec 2018 12:10:30 -0500 Subject: [PATCH] fix: prevent calling setState in TransitionGroup if it has been unmounted (#435) --- src/TransitionGroup.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/TransitionGroup.js b/src/TransitionGroup.js index 919c5e92..1e1e0fa9 100644 --- a/src/TransitionGroup.js +++ b/src/TransitionGroup.js @@ -104,6 +104,11 @@ class TransitionGroup extends React.Component { componentDidMount() { this.appeared = true + this.mounted = true + } + + componentWillUnmount() { + this.mounted = false } static getDerivedStateFromProps( @@ -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() {