0
{
    "_id" : ObjectId("577c4b18b1216fd9cb1a2ffc"),
    "username" : "John",
    "todolist" : [ 
        {
            "_id" : ObjectId("577c4b36b1216fd9cb1a2ffd"),
            "newtodo" : {
                "tittle" : "Playing football"
            }
        }
    ],
    "dateAdded" : ISODate("2016-07-06T00:04:40.914Z"),
    "__v" : 0
}

我这样写道具数据库,但标题出错

<p className={styles['author-name']}><FormattedMessage id="by" /> {props.user.username}</p>
      <p className={styles['author-name']}>{props.user.todolist['newtodo.tittle']}</p>

我需要知道如何喜欢 Proptypes.shape

user: PropTypes.shape({
 username: PropTypes.string.isRequired,
    todolist:PropTypes.arrayOf(PropTypes.shape({
        newtodo: PropTypes.objectOf(PropTypes.string)({
            tittle:PropTypes.string.isRequired,
        })
})).isRequired,

请帮帮我 TT 我是 React 的新手

4

1 回答 1

0

最有可能的是,它应该是:

user: PropTypes.shape({
  username: PropTypes.string.isRequired,
  todolist: PropTypes.arrayOf(PropTypes.shape({
    newtodo: PropTypes.shape({
      tittle: PropTypes.string.isRequired
    })
  })).isRequired
})

newtodo对象应该用 描述PropTypes.shape,而不是Proptypes.objectOf

于 2016-07-06T05:41:57.580 回答