简体   繁体   English

来自react-intl的FormattedNumber组件不起作用

[英]FormattedNumber component from react-intl doesn't work

I am trying to use the component FormattedNumber from the react-intl library but I can't make it to work. 我试图使用react-intl库中的组件FormattedNumber ,但我无法使其工作。

<IntlProvider
    locale="en-US"
    messages={locales['en-US']}
>
    <div>
        <FormattedNumber value={123456} />
        <FormattedNumber value="123456" />
    </div>
</IntlProvider>

This only returns the value the way I passed it to the component, wrapped with a span, but it doesn't format the number. 这只返回我传递给组件的方式,用span包装,但它不格式化数字。

I get an error in the console: 我在控制台中收到错误:

[React Intl] Error formatting number. [React Intl]错误格式化编号。 TypeError: Bind must be called on a function TypeError:必须在函数上调用Bind

The FormattedMessage component works fine for all my translations, the locale is set to en-US , so I don't think the issue comes from the IntlProvider or something else. FormattedMessage组件适用于我的所有翻译,语言环境设置为en-US ,所以我不认为问题来自IntlProvider或其他东西。

在此输入图像描述

I am using the latest version of the library, 2.0.1 我正在使用最新版本的库2.0.1

Any idea? 任何想法?

I have the same issue. 我有同样的问题。 In my case problem was in global definition window.Intl. 在我的情况下问题是在全局定义窗口.Intl。 It rewrite the original lib object and lose functions context 它重写原始的lib对象并丢失函数上下文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React组件或从存储数据中替换字符串文字的策略,类似于react-intl - React component, or strategy to replace string literals from stored data similar to react-intl react-intl将react组件作为formatMessage中的占位符 - react-intl render react component as placeholder in formatMessage 使用react-intl在组件外部翻译消息密钥 - using react-intl to translate a message key outside a component 在同一文件中使用的 react-intl 组件的 Typescript 类型 - Typescript type for react-intl component used inside same file React-Intl如何从变量切换语言环境和消息 - React-Intl how to switch locale and messages from variable React-Intl:从api响应加载新字符串 - React-Intl: Load new strings from api response 将 react-intl 与 react-table 集成 - Integrate react-intl with react-table React-intl在Safari v8.0.8上禁用react-router的链接组件onClick事件 - React-intl disable react-router's Link component onClick event on Safari v8.0.8 在玩笑测试时如何在react component方法中将react-intl作为参数传递,抛出&#39;TypeError:intl.formatMessage不是一个函数&#39; - how to pass react-intl as argument in react component method while jest testing, throws 'TypeError: intl.formatMessage is not a function' react-intl不会更改占位符的值 - react-intl not changing placeholder value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM