updating componentwillreceiveprops so that it is flexible for a usecase where youre updating the props passed down to a child state (i.e. you favorited a card and added to parent state and you're passing down that state to child as a prop) after an action and you dont want the cards to restart

This commit is contained in:
Yong Cho
2018-02-27 11:31:14 -06:00
parent 7c27b5da97
commit 52928fc10d

View File

@@ -136,9 +136,13 @@ export default class CardStack extends Component {
}
componentWillReceiveProps(nextProps){
this.setState({
if (nextProps.children !== this.props.children) {
this.setState({
cards: nextProps.children,
cardA: nextProps.children[0],
cardB: nextProps.children[1],
});
}
}
_resetCard(){