Created
October 28, 2019 19:59
-
-
Save schabluk/4901181cee71f3ec1641b7b5aea28f23 to your computer and use it in GitHub Desktop.
IntlProvider & Redux StoreProvider
This file contains hidden or 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 { IntlProvider } from 'react-intl' | |
import { Provider as StoreProvider, connect } from 'react-redux' | |
import { createStore } from 'redux' | |
import { appStore } from './store' | |
import messages_de from './translations/de.json' | |
import messages_en from './translations/en.json' | |
import messages_pl from './translations/pl.json' | |
/** | |
* Translations. | |
*/ | |
const messages = { | |
de: messages_de, | |
en: messages_en, | |
pl: messages_pl, | |
} | |
/** | |
* Aplication Store. | |
*/ | |
const store = createStore(appStore) | |
const ConnectedIntlProvider = connect(state => { | |
const { language } = state | |
return { locale: language, messages: messages[language] } | |
})(IntlProvider) | |
/** | |
* Top-Level context Providers. | |
*/ | |
const Providers = ({ children }) => { | |
return ( | |
<StoreProvider store={store}> | |
<ConnectedIntlProvider> | |
{children} | |
</ConnectedIntlProvider> | |
</StoreProvider> | |
) | |
} | |
export default Providers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment