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: 'ssdjksd@dkskd.com',
  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?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
apollo24
  • 303
  • 4
  • 16
  • 2
    Does this answer your question? [JS log object why is showing \[object Object\]](https://stackoverflow.com/questions/47842644/js-log-object-why-is-showing-object-object) – imjared Apr 27 '20 at 20:04
  • Thank u. Didn't know you cant concatenate a string with an object – apollo24 Apr 27 '20 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. – Emile Bergeron Apr 27 '20 at 20:11

1 Answers1

2

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

imjared
  • 19,492
  • 4
  • 49
  • 72