Created
March 10, 2018 14:01
-
-
Save MicroBenz/a44dde112fb753ab6d641b0ccc844465 to your computer and use it in GitHub Desktop.
React Context
This file contains hidden or 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 MessageList extends React.Component { | |
getChildContext() { | |
// Declare context object | |
return {color: "purple"}; | |
} | |
render() { | |
const children = this.props.messages.map((message) => | |
<Message text={message.text} /> | |
); | |
return <div>{children}</div>; | |
} | |
} | |
MessageList.childContextTypes = { | |
color: PropTypes.string // Like prop-types but for context | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment