Reputation: 44967
I have a component (popup) that renders outside of the tree (aka portal), therefore losing the context of IntlProvider
:
<IntlProvider locale="en">
<App />
</IntlProvider>
// * <- renders here
Redux solves the same issue by allowing to pass store instance as a prop for the component:
import store from "./store";
const Component = () => <Popup store={store} />;
Is there a similar approach I can use for ReactIntl?
Upvotes: 0
Views: 1892
Reputation: 1
if you dont want to wrap your component into HOC, useIntl hook is good too :)
Upvotes: -1
Reputation: 7424
You can use injectIntl HOC with injects intl
into your component.
Simply change you code from:
const Component = () => <Popup ... />
to:
import { injectIntl } from 'react-intl';
const Component = ({ intl }) => <Popup intl={intl} />
export default injectIntl(Component)
Upvotes: 0