Skip to content

Instantly share code, notes, and snippets.

@kazagkazag
Created July 13, 2016 08:01
Show Gist options
  • Save kazagkazag/59f71aefff9aba55832dbb04e4f32741 to your computer and use it in GitHub Desktop.
Save kazagkazag/59f71aefff9aba55832dbb04e4f32741 to your computer and use it in GitHub Desktop.
class Button extends React.Component {
render() {
return <button style={{background: this.context.color}}> {this.props.children}</button>;
}
}
Button.contextTypes = {
color: React.PropTypes.string
};
class Message extends React.Component {
render() {
return <div>{this.props.text} <Button>Delete</Button></div>;
}
}
class MessageList extends React.Component {
getChildContext() {
return {color: "purple"};
}
render() {
const children = this.props.messages.map((message) =>
<Message text={message.text} />
);
return <div>{children}</div>;
}
}
MessageList.childContextTypes = {
color: React.PropTypes.string
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment