Skip to content

Instantly share code, notes, and snippets.

@ericf ericf/messages.js
Last active Nov 9, 2015

Embed
What would you like to do?
/*
* Copyright 2015, Yahoo Inc.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
import {Component, Children, PropTypes} from 'react';
import {intlShape} from '../types';
import {invariantIntlContext} from '../utils';
export default class MessagesProvider extends Component {
constructor(props, context) {
super(props, context);
invariantIntlContext(context);
}
getChildContext() {
return {
intl: {
...this.context.intl,
messages: this.props.messages,
},
};
}
render() {
return Children.only(this.props.children);
}
}
MessagesProvider.displayName = 'MessagesProvider';
MessagesProvider.contextTypes = {
intl: intlShape,
};
MessagesProvider.propTypes = {
messages: PropTypes.object,
};
MessagesProvider.defaultProps = {
messages: {},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.