Skip to content

Instantly share code, notes, and snippets.

@ericf
Last active November 9, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericf/c7296c5bd064df02c16e to your computer and use it in GitHub Desktop.
Save ericf/c7296c5bd064df02c16e to your computer and use it in GitHub Desktop.
/*
* 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