Created
July 13, 2016 08:01
-
-
Save kazagkazag/59f71aefff9aba55832dbb04e4f32741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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