Child object appears as 'Undefined', but an object’s previous level shows the value

Asked

Viewed 53 times

0

The field this.props.usuario.user.guia is as undefined, but when I log the object this.props.usuario.user appears with value. It makes no sense to me.

Log code:

if (!this.props.usuario.logout) { 
    if (prevProps.usuario.user !== this.props.usuario.user) {
        console.tron.log(this.props.usuario);
        console.tron.log(this.props.usuario.user);
        console.tron.log(this.props.usuario.user.guia);
    }
}

Imagem do resultado do LOG

  • Why doesn’t it make sense? A child object can be empty, impossible it would be for the object to be empty and have a child object with value....!

  • Good morning! The image is not quite clear what it matches.. The second debug item refers to what? You can show the console output?

  • 1

    Good morning! It’s really hard to decipher the above code, try to put only the console.log() of the working line and the other line of the error commented on the right side!! ;)

  • Following people, when I put in my log the object this.props.user.user it shows me those items of the image(user, tourist, name...) with value, but when I try to use this.props.user.user.tab, for example, it presents me Undefined, q in the log, from the previous line, he displayed value

  • that Undefined line of the log image is represented by the console.tron.log(this.props.user.user.tab) command. The line with value is represented by the console.tron.log(this.props.user.user);

    1. Wouldn’t the second log block be this.props.user? If so, wouldn’t this.props.user.guia be right? 2. Another try: Is the object not string? Try JSON.parse(this.props.user.user). tab ... I can’t think of any other situation, but I suggest you note that there is nothing asynchronous going on that could be altering the state of your application and causing these problems.
Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.