Easy-peasy: How to console.log state inside the actions

Created on 26 Feb 2019  路  4Comments  路  Source: ctrlplusb/easy-peasy

I have an issue regarding Actions. When I console.log the state inside an action, i get a proxy which I suspect is Immer underneath.

0: Proxy
[[Handler]]: null
[[Target]]: null
[[IsRevoked]]: true
length: 1

What do I have to do to get the value from the proxy apart from JSON.stringify?

Most helpful comment

@ctrlplusb Thanks for your reply. Using original seems to do the trick. I will leave this here for reference

import { original } from 'immer'

console.log(original(state.myObject))

Out of interests sake. Does the redux dev tools not help with this case?

Well unless I am mistaken redux dev tools show before and after, in my case I wanted to see what happens between before and after, in my action.

All 4 comments

Hmmm, yeah, not ideal but you may need to extract the original object as discussed in the immer docs:

https://github.com/mweststrate/immer#extracting-the-original-object-from-a-proxied-instance

Out of interests sake. Does the redux dev tools not help with this case?

@ctrlplusb Thanks for your reply. Using original seems to do the trick. I will leave this here for reference

import { original } from 'immer'

console.log(original(state.myObject))

Out of interests sake. Does the redux dev tools not help with this case?

Well unless I am mistaken redux dev tools show before and after, in my case I wanted to see what happens between before and after, in my action.

Out of interests sake. Does the redux dev tools not help with this case?

Just to give more information on this, I don't really use Redux tools. I've always found leaving console a little too much trouble ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

coooolers picture coooolers  路  5Comments

ifyoumakeit picture ifyoumakeit  路  5Comments

gino8080 picture gino8080  路  5Comments

Windynik picture Windynik  路  5Comments

andreiQuant picture andreiQuant  路  6Comments