Skip to content

Instantly share code, notes, and snippets.

@alexandrzavalii
Last active March 24, 2019 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandrzavalii/0775fced8a009f474a9b090219a65bbe to your computer and use it in GitHub Desktop.
Save alexandrzavalii/0775fced8a009f474a9b090219a65bbe to your computer and use it in GitHub Desktop.
class DumbosParent extends React.Component {
state = { availableShoes: 6 };
sellShoes = () => {
this.setState(({ availableShoes }, props) => ({
availableShoes: availableShoes > 1 && availableShoes - 1
}));
};
render() {
return (
<div>
<h1>I am Dumbos Father. I keep track of shoes.</h1>
<p>available shoes: {this.state.availableShoes}</p>
<button onClick={this.sellShoes}>Sell one pare of shoes</button>
<Dumbo availableShoes={this.state.availableShoes} />
<AnotherComponent availableShoes={this.state.availableShoes} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment