From 52928fc10db50c522ebb975bb27139852d15ec19 Mon Sep 17 00:00:00 2001 From: Yong Cho Date: Tue, 27 Feb 2018 11:31:14 -0600 Subject: [PATCH] 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 --- CardStack.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CardStack.js b/CardStack.js index 552eb1b..3502d92 100644 --- a/CardStack.js +++ b/CardStack.js @@ -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(){