在一个ts文件中的独立函数中如何使用umi的useIntl来实现国际化?使用 import { formatMessage } from 'umi'的话有报警信息。
这不是bug。
这是因为 intl 依赖指定的react 上下文,否则就会无法生效或者告警。
然后说回问题,你这个独立的函数文件,将来不是要用在 react 组件里么?具体做什么用的
import { getIntl, getLocale } from 'umi';
function test() {
const intl = getIntl(getLocale());
console.log(
intl.formatMessage({
id: 'system.hello',
description: 'Hello',
})
);
}
Most helpful comment