react-intl cosnt< FormattedMessage/>正在给[object object]作为结果 [英] React-intl cosnt <FormattedMessage /> is giving [object object] as result
本文介绍了react-intl cosnt< FormattedMessage/>正在给[object object]作为结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用"react-intl":"^ 2.4.0"和"react":"^ 16.2.0".
I am using "react-intl": "^2.4.0", and "react": "^16.2.0".
我正在尝试将FormattedMessage标签的输出分配给一个常量,并将其放在输入标签的占位符中.
I am trying to assign the output of FormattedMessage tag to a constant and put it in the input tag placeholder.
预期的输出输入"字段,其中包含使用相应语言的文本,但该字段正在[对象对象]出现在文本框中.
Expected Output Input field with text in the respective language in it but it is coming [object object] inside the text box.
推荐答案
<FormattedMessage />
是无法放置在需要原始字符串的placeholder
上的组件.
<FormattedMessage />
is a component which cannot be placed to placeholder
which expects a raw String.
import {injectIntl} from 'react-intl';
class TestComponent extends React.Component{
render(){
const { intl } = this.props;
return (
<input placeholder={intl.formatMessage({ id: "loginPage.username", defaultMessage: 'username'})}/>
)
}
}
export default injectIntl(TestComponent);
这篇关于react-intl cosnt< FormattedMessage/>正在给[object object]作为结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文