Replies: 2 comments
-
|
You can do this, export function deepClone<T>(value: T): T {
if (typeof structuredClone === 'function') {
return structuredClone(value)
}
// fallback:You may use lodash/cloneDeep or your own implementation.
// return cloneDeep(value)
// or simple:
return JSON.parse(JSON.stringify(value))
}
const nextState = create(state, (draft)=> {
// some logic
return rawReturn(deepClone(state));
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Ya, thanks, of course I understand how to deep clone, So, no built-in for this in mutative, I understood. Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So - question is simple. I need deep copy of value.
I try this create(v, (_)=>undefined)
I try this create(v, (_draft)=>draft)
but these are return original v, not copy
rawReturn(draft) return draft proxy.
So is there a way or I should use external libs for this?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions