Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created March 10, 2018 13:57
Show Gist options
  • Save MicroBenz/e9e5cd09635efcf5e42fc67c9721e100 to your computer and use it in GitHub Desktop.
Save MicroBenz/e9e5cd09635efcf5e42fc67c9721e100 to your computer and use it in GitHub Desktop.
React Context
class Button extends React.Component {
render() {
return (
<button style={{background: this.props.color}}>
{this.props.children}
</button>
);
}
}
class Message extends React.Component {
render() {
return (
<div>
{this.props.text} <Button color={this.props.color}>Delete</Button>
</div>
);
}
}
class MessageList extends React.Component {
render() {
const color = "purple";
const children = this.props.messages.map((message) =>
<Message text={message.text} color={color} />
);
return <div>{children}</div>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment