0
{
    "_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

<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

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

Alexandr Lazarev
  • 12,554
  • 4
  • 38
  • 47
Bee BBFL
  • 9
  • 2

1 Answers1

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.

Alexandr Lazarev
  • 12,554
  • 4
  • 38
  • 47
  • Thank you but when I test on localhost it is error like this Uncaught (in promise) TypeError: Cannot read property 'newtodo.tittle' of undefined – Bee BBFL Jul 06 '16 at 05:50