Reactjs 有没有办法在react组件外部获取当前intl值
我们可以在react组件之外获取当前intl(区域设置)值吗Reactjs 有没有办法在react组件外部获取当前intl值,reactjs,react-intl,Reactjs,React Intl,我们可以在react组件之外获取当前intl(区域设置)值吗 const locales = { locale: 'en', messages: {}, }; import { IntlProvider, addLocaleData } from 'react-intl'; //below is for creating const intlProvider = new IntlProvider(locales, {}); const { intl } = intlProvider
const locales = {
locale: 'en',
messages: {},
};
import { IntlProvider, addLocaleData } from 'react-intl';
//below is for creating
const intlProvider = new IntlProvider(locales, {});
const { intl } = intlProvider.getChildContext();
//is there any code snippet to get current value from IntlProvider?
是的,您可以使用
createIntl
API:以上代码用于创建。我需要一些可以在JavaScript帮助文件中显示当前intl值的代码片段,我是说您不应该从intlProvider.getChildContext()
中获取intl
对象,因为在以后的intl版本中,这不再有效。您应该改为使用createIntl
,并将其传递下去