Currently I have the following code to expose react-intl to non-components, but it throws an error for intl as undefined.
I have created a separate component as \'Curren
There's a new way to do it pretty easily with createIntl, it returns an object that you can use outside React components. Here's an example from the documentation.
import {createIntl, createIntlCache, RawIntlProvider} from 'react-intl'
// This is optional but highly recommended
// since it prevents memory leak
const cache = createIntlCache()
const intl = createIntl({
locale: 'fr-FR',
messages: {}
}, cache)
// Call imperatively
intl.formatNumber(20)
// Pass it to IntlProvider
{foo}
I personally store the intl object in Redux store so I can access it everywhere in my app.