【发布时间】:2018-03-02 15:11:56
【问题描述】:
所以我正在尝试向我的组件对象添加一个形状。该对象从服务器加载,因此从一开始就不存在。但是当我将形状添加到 Proptypes 时。它不断抛出它被标记为必需但不是的错误。
shape 或 objectOf 是否会自动添加 isRequired 值?
TopicsList.propTypes = {
topicsObject: PropTypes.shape(reportsTopicsObjectResultShape),
};
还有形状:
export const reportsTopicObject = PropTypes.shape({
avg_rating_ord: PropTypes.number,
cards_with_comments: PropTypes.number,
cards_without_comments: PropTypes.number,
number_of_questions: PropTypes.number,
rating_count: PropTypes.number,
scale_version_id: PropTypes.string,
scale_id: PropTypes.string,
last_answered_at: PropTypes.string,
id: PropTypes.string,
type: PropTypes.string,
name: PropTypes.shape(translatedObjectSystem),
description: PropTypes.shape(translatedObjectSystem)
});
export const reportsTopicsObjectResultShape = PropTypes.shape({
topics_distribution: PropTypes.shape({
general: PropTypes.number,
groups: PropTypes.number,
people: PropTypes.number
}),
topic_list: PropTypes.objectOf(reportsTopicObject)
});
我仍然收到错误:
Failed prop type: The prop `topicsObject.isRequired` is marked as
required in `TopicsList`, but its value is `undefined`.
确实,开头是undefined,这没关系,但我不希望它是必需的。
【问题讨论】:
标签: javascript reactjs react-redux react-proptypes