我缩小了范围以发现错误仅在我尝试传递 React-Moment documentation 中描述的 <Moment />
组件时发生。到目前为止,我还没有找到任何特定于这个包的解释,希望有人有类似的问题!
文档说明了这样的用法:
import Moment from 'react-moment';
// then within the class component:
return (
const dateToFormat = '1976-04-19T12:59-0500';
<Moment>{dateToFormat}</Moment>
);
我想采用这样的原始日期字符串:
<Text>Created {this.props.postDate}</Text>
存储方式如下:
"postDate": "2019-01-31T04:13:31.224Z"
但到目前为止,无论何时我添加
<Moment>{this.props.postDate}</Moment>
,无论是在现有 <Text />
块的外部还是内部,我都会变红:最佳答案
它在文档中:
https://github.com/headzoo/react-moment#usage-with-react-native
<Moment element={Text}>{dateToFormat}</Moment>
关于react-native - React-Moment 给出 : "Invariant Violation: Text strings must be rendered within a <Text> component",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54497672/