Last active
October 26, 2018 08:25
-
-
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
This file contains 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
<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> |
This file contains 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
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