Skip to content

Instantly share code, notes, and snippets.

@alexandrzavalii
Last active March 24, 2019 17:49
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/6563aaae654814dbda6d44c3a8356424 to your computer and use it in GitHub Desktop.
Save alexandrzavalii/6563aaae654814dbda6d44c3a8356424 to your computer and use it in GitHub Desktop.
class Dumbo extends React.Component {
state = { clothing: null, firstChild: null, secondChild: null };
handleState = () => {
this.setState({
clothing: "jeans",
firstChild: "shoes",
secondChild: "hat"
});
};
render() {
return (
<div>
<h1>Hey, my name is Dumbo. </h1>
<p> I am wearing {this.state.clothing} today.</p>
<button onClick={this.handleState}>dress up</button>
<FirstChild clothing={this.state.firstChild} />
<SecondChild clothing={this.state.secondChild} />
</div>
);
}
}
const FirstChild = props => <p>I am John, and I am wearing {props.clothing} today.</p>;
const SecondChild = props => <p>I am Max, and I am wearing {props.clothing} today.</p>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment