debug
This helper is useful in the context of actions.
Actions use the immer library under the hood in order to convert mutative updates into immutable ones. Therefore if you try to console.log
your state within an action you will see wrapping Proxy
objects printed out.
Use this helper in order to get the original state
value that was provided to your action in its native representation.
Before:
const model = {
increment: action((state, payload) => {
console.log(state); // 👈 prints a Proxy object
state.count += 1;
})
}
After:
import { debug } from 'easy-peasy';
const model = {
increment: action((state, payload) => {
console.log(debug(state)); // 👈 prints the "native" state representation
state.count += 1;
})
}
Note: this helper will only return the original state that was provided to your action. Any mutations that are applied to the state within your action will not be represented.
If you have set the
disableImmer
configuration value on the store you will not need to use this helper.
← createTransform memo →