我正在使用 "react-intl": "^2.4.0"
, 和 "react": "^16.2.0"
.
我正在尝试分配 <FormattedMessage/>
的输出标记为常量并将其放在输入标记占位符中。
预期的输出输入字段,其中包含相应语言的文本,但它在文本框中出现 [object object]。
最佳答案
<FormattedMessage />
是无法放置到 placeholder
的组件它需要一个原始字符串。
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);
关于reactjs - React-intl const <FormattedMessage/> 给出 [object object] 作为结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52423291/