From 9d0c83971ba237a4b8daaca6bb2ef9325420d892 Mon Sep 17 00:00:00 2001 From: Devin Fee Date: Thu, 8 Nov 2018 11:28:01 -0800 Subject: [PATCH] fix(react): moves this.connectToAbility to the setState callback (#129) fixes #128 --- packages/casl-react/src/Can.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/casl-react/src/Can.js b/packages/casl-react/src/Can.js index b80624cab..7bce73860 100644 --- a/packages/casl-react/src/Can.js +++ b/packages/casl-react/src/Can.js @@ -53,8 +53,10 @@ export default class Can extends PureComponent { componentWillReceiveProps(props) { if (props.ability && this.state.ability !== props.ability) { - this.setState({ ability: props.ability }); - this.connectToAbility(props.ability); + this.setState( + { ability: props.ability }, + () => { this.connectToAbility(this.state.ability); } + ); } else { this.recheck(props); }