From 1d6fadd7724819a26eea60c8b47cc26a7bc989ca Mon Sep 17 00:00:00 2001 From: Wesley de Souza Date: Thu, 25 May 2017 15:41:05 -0400 Subject: [PATCH] Prevent `this.setState` if there is no component On `_handleDoneLeaving`, prevent calling `setState` if the component is unmounted. This was triggering this error: > Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the ReactTransitionGroup component. --- index.js | 2 +- src/TransitionGroup.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index bf4045fa..3666b25f 100644 --- a/index.js +++ b/index.js @@ -437,7 +437,7 @@ var TransitionGroup = function (_React$Component) { if (currentChildMapping && currentChildMapping.hasOwnProperty(key)) { // This entered again before it fully left. Add it again. _this.performEnter(key); - } else { + } else if (component) { _this.setState(function (state) { var newChildren = Object.assign({}, state.children); delete newChildren[key]; diff --git a/src/TransitionGroup.js b/src/TransitionGroup.js index 2cba6a6a..726b3fed 100644 --- a/src/TransitionGroup.js +++ b/src/TransitionGroup.js @@ -174,7 +174,7 @@ class TransitionGroup extends React.Component { if (currentChildMapping && currentChildMapping.hasOwnProperty(key)) { // This entered again before it fully left. Add it again. this.performEnter(key); - } else { + } else if (component) { this.setState((state) => { let newChildren = Object.assign({}, state.children); delete newChildren[key];