0

I'm dispatching an action, which gets a response from a route in this format :

res.json({
  token,
  user: {
    id: user.id,
    email: user.email,
    password: user.password,
  },
})

The promise does resolve and the new user is saved to the DB. But on the reducer, which looks like this :

case ADD_USER:
  console.log(`payload is ${action.payload.user}`)
  return {
    ...state,
    users: [...state.users, action.payload.user],
  }

The payload I get in chrome console is this :

payload is [object Object]

Which should look like this :

user: {
  id: '5ea737af99a72f29d4864843',
  email: '[email protected]',
  password: '$2a$10$wqVQaOFTTD5nTB/eQN79xuSlFy0gQ8kgz3QKuB86BVs1ke6MMPFX6'
}

The data is stored correctly in state and I can see it in Redux Dev tools,

But how can I see the console.log right too?

3
  • 2
    Does this answer your question? JS log object why is showing [object Object] Commented Apr 27, 2020 at 20:04
  • Thank u. Didn't know you cant concatenate a string with an object Commented Apr 27, 2020 at 20:07
  • 1
    @apollo24 you can concatenate an object to a string, but unless you define a custom toString function on that object, you'll get [object Object], which is the default string representation of an object. Commented Apr 27, 2020 at 20:11

1 Answer 1

2

change it to console.log('payload', action.payload.user);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.