Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created March 10, 2018 14:01
Show Gist options
  • Save MicroBenz/a44dde112fb753ab6d641b0ccc844465 to your computer and use it in GitHub Desktop.
Save MicroBenz/a44dde112fb753ab6d641b0ccc844465 to your computer and use it in GitHub Desktop.
React Context
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