失败的道具类型:道具`children`在`e`中被标记为必需,但其值为'null`

时间:2017-10-12 02:31:23

标签: reactjs

在我的React应用程序中,我收到以下错误,但它没有告诉我它在哪里发生。知道如何确定其位置吗?我唯一拥有<table>的地方对此错误似乎没有任何意义。

enter image description here

更新: 这是this.props.children组件。

Timeline

这是import React, { PropTypes } from 'react'; import PerfectScrollBar from 'react-perfect-scrollbar'; // Components import TimelineEntry from './timelineEntry'; // Defaults import { AvatarUrl } from '../../../../enum/defaults'; const Timeline = ({ member, conversationId, messages, activeMessageId, handleClickMessageSelected }) => { return ( <div className=" height-100 padding-top-70"> <div className="padding-15" style={{ position: 'absolute', top: '0', left: '0' }}> {typeof conversationId !== "undefined" && conversationId !== "" ? <div className="timeline-item-msg" id="msc-newConversationMessage"> <img src={member.avatar ? member.avatar.smallAvatarUrl : AvatarUrl.avatar} className="tim-image" /> <div className="tim-msg"> <div className="tim-msg-body cursor-pointer border-radius"> New Message </div> </div> </div> : null } </div> <div className="height-100 position-relative padding-15"> <PerfectScrollBar> { messages.length > 0 ? messages.map(item => <TimelineEntry key={item.id} entry={item} activeMessageId={activeMessageId} handleClickMessageSelected={handleClickMessageSelected} />) : null } </PerfectScrollBar> </div> </div> ); } Timeline.PropTypes = { member: PropTypes.object.isRequired, conversationId: PropTypes.string.isRequired, messages: PropTypes.array.isRequired, activeMessageId: PropTypes.string.isRequired, handleClickMessageSelected: PropTypes.func.isRequired }; export default Timeline; 组件:

TimelineEntry

1 个答案:

答案 0 :(得分:5)

您在PerfectScrollBar组件中使用的Timeline组件具有propType children: PropTypes.node.isRequired。 (代码https://github.com/goldenyz/react-perfect-scrollbar/blob/master/src/scrollbar.js

Timeline组件中,当messages.length为0时,您正在呈现null;这导致children没有PerfectScrollBar呈现,而<div></div>又提供propType警告。

这样做的解决方法是渲染一个空div null而不是PerfectScrollBar,以便满足char* buf; // assumed allocated int num = 0; 的propTypes。