From cb84952cc6ae13b430fec1807d13b525fb8e25f0 Mon Sep 17 00:00:00 2001 From: Christian Ivicevic Date: Sun, 16 Dec 2018 13:30:04 +0100 Subject: [PATCH] Fix setState calls using updater functions React does not guarantee that the state changes are applied immediately. It is best practice to use an updater function if the new state relies on the current state. --- .../docs-app/src/examples/core-examples/panelStackExample.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docs-app/src/examples/core-examples/panelStackExample.tsx b/packages/docs-app/src/examples/core-examples/panelStackExample.tsx index f16c50ee9c..68c3a67375 100644 --- a/packages/docs-app/src/examples/core-examples/panelStackExample.tsx +++ b/packages/docs-app/src/examples/core-examples/panelStackExample.tsx @@ -46,13 +46,13 @@ export class PanelStackExample extends React.PureComponent { - this.setState({ currentPanelStack: [newPanel, ...this.state.currentPanelStack] }); + this.setState(state => ({ currentPanelStack: [newPanel, ...state.currentPanelStack] })); }; private removeFromPanelStack = (_lastPanel: IPanel) => { // In this example, the last panel is always the one closed. // Using `this.props.closePanel()` is one way to violate this. - this.setState({ currentPanelStack: this.state.currentPanelStack.slice(1) }); + this.setState(state => ({ currentPanelStack: state.currentPanelStack.slice(1) })); }; }