Skip to content

Commit

Permalink
fix(react): moves this.connectToAbility to the setState callback (#129)
Browse files Browse the repository at this point in the history
fixes #128
  • Loading branch information
dfee authored and stalniy committed Nov 8, 2018
1 parent 774457a commit 9d0c839
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/casl-react/src/Can.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9d0c839

Please sign in to comment.