Skip to content

Instantly share code, notes, and snippets.

@bmihelac
Last active October 26, 2018 08:25
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 bmihelac/647d4a5d7c1005cfa94246b9744cb4ed to your computer and use it in GitHub Desktop.
Save bmihelac/647d4a5d7c1005cfa94246b9744cb4ed to your computer and use it in GitHub Desktop.
react-intl message lookup bubbling, see: https://github.com/yahoo/react-intl/issues/1109
<IntlProvider
locale={locale}
messages={messages.app}
>
<NestedIntlProvider
locale={locale}
messages={messages.greeting}
>
<div>
<FormattedMessage
id="app.title"
defaultMessage="React Intl Nested Messages Example"
/>
<FormattedMessage
id="greeting.welcome_message"
defaultMessage="Welcome"
/>
</div>
</NestedIntlProvider>
</IntlProvider>
import React from 'react'
import { injectIntl, IntlProvider } from 'react-intl'
/**
* Merges previous and current messages
* See: https://github.com/yahoo/react-intl/issues/1109
*/
const NestedIntlProvider = ({intl, ...props}) => {
const { messages, ...otherProps } = props
const nestedMessages = {
...intl.messages,
...messages
}
return <IntlProvider messages={nestedMessages} {...otherProps} />
}
export default injectIntl(NestedIntlProvider)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment