{
"_id" : ObjectId("577c4b18b1216fd9cb1a2ffc"),
"username" : "John",
"todolist" : [
{
"_id" : ObjectId("577c4b36b1216fd9cb1a2ffd"),
"newtodo" : {
"tittle" : "Playing football"
}
}
],
"dateAdded" : ISODate("2016-07-06T00:04:40.914Z"),
"__v" : 0
}
I write props database like this but it gets error on tittle
我写这样的道具数据库,但它在tittle上得到错误
<p className={styles['author-name']}><FormattedMessage id="by" /> {props.user.username}</p>
<p className={styles['author-name']}>{props.user.todolist['newtodo.tittle']}</p>
And I need to know how to like in Proptypes.shape
我需要知道在Proptypes.shape中如何喜欢
user: PropTypes.shape({
username: PropTypes.string.isRequired,
todolist:PropTypes.arrayOf(PropTypes.shape({
newtodo: PropTypes.objectOf(PropTypes.string)({
tittle:PropTypes.string.isRequired,
})
})).isRequired,
Please Help me please T-T I am a new in React
请帮帮我T-T我是React的新手
1 个解决方案
#1
0
Most probably, it should be:
最有可能的是,它应该是:
user: PropTypes.shape({
username: PropTypes.string.isRequired,
todolist: PropTypes.arrayOf(PropTypes.shape({
newtodo: PropTypes.shape({
tittle: PropTypes.string.isRequired
})
})).isRequired
})
newtodo
object should be described with PropTypes.shape
, not with Proptypes.objectOf
.
应使用PropTypes.shape描述newtodo对象,而不是使用Proptypes.objectOf。
#1
0
Most probably, it should be:
最有可能的是,它应该是:
user: PropTypes.shape({
username: PropTypes.string.isRequired,
todolist: PropTypes.arrayOf(PropTypes.shape({
newtodo: PropTypes.shape({
tittle: PropTypes.string.isRequired
})
})).isRequired
})
newtodo
object should be described with PropTypes.shape
, not with Proptypes.objectOf
.
应使用PropTypes.shape描述newtodo对象,而不是使用Proptypes.objectOf。