apollo24
apollo24

Reputation: 313

Getting an [object Object] instead of actual data in console.log

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?

Upvotes: 0

Views: 646

Answers (1)

imjared
imjared

Reputation: 20554

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

Upvotes: 2

Related Questions