-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist middleware incompatible with Map
and Set
#618
Comments
Will add repro steps shortly! |
https://github.com/nc/repro-zustand-immer-persist Wrote a simple Vite app to repro this issue. Here's the main code:
And the error:
It would seem all the |
By default, export const store = create<Store>(persist((set) => ({
foo: new Set(),
}), {
name: 'persist-store',
serialize: (data) => {
return JSON.stringify({
...data,
state: {
...data.state,
foo: Array.from(data.state.foo as Set<unknown>),
},
});
},
deserialize: (value) => {
const data = JSON.parse(value);
data.state.foo = new Set(data.state.foo);
return data;
},
})); |
Map
and Set
As seen in: - pmndrs#652 - pmndrs#1143 - pmndrs#457 - pmndrs#618 The documentation lacks an example that would both explain and highlight actions and nested objects in persisted stores. Personally, I had to use more time than I hoped for to find [this comment](pmndrs#1143 (comment)) in an issue, instead in the docs. The docs has all the puzzle pieces - but requires larger understanding of how these pieces work together. With this section using information from above outlined issues, I hope to make things a bit more clear.
Is this a KP? Wondering what the best workaround is? Even just importing persist seems to cause this.
The text was updated successfully, but these errors were encountered: