反应矩给出了:“违反不变:文本字符串必须在一个被渲染 零件”

问题描述 投票:1回答:1

我已经收窄下来发现,只有当我尝试作为<Moment />描述传递React-Moment documentation组件发生错误。到目前为止,我还没有发现针对该包的任何解释,并希望有人在那里已经有过类似的问题!

该文档拼出这样的用法:

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 />块,我得到的红色内:

enter image description here

react-native momentjs
1个回答
4
投票

这是在文档中:

https://github.com/headzoo/react-moment#usage-with-react-native

<Moment element={Text}>{dateToFormat}</Moment>
© www.soinside.com 2019 - 2024. All rights reserved.