zustandjs / zustand-slices

A slice utility for Zustand
MIT License
137 stars 6 forks source link

Slices + persist #21

Closed Simoon-F closed 4 weeks ago

Simoon-F commented 1 month ago

In this example, if I only want to store countSlice , can it be adjusted like this?

https://t.co/7AognoqHWV

const useCountStore = create()((...config) => ({
  ...devtools(persist(withSlices(countSlice), { name: 'foo' }))(...config),
  ...withSlices(textSlice)(...config),
}));
dai-shi commented 1 month ago

I don't think it works. Did you try?

You should use partialize option with persist.

Simoon-F commented 4 weeks ago

@dai-shi In this example, I made a temporary adjustment, which turned out to be effective, but there was a TS type error prompt. I am not sure whether this method is correct, but subconsciously I think it seems not very elegant.

Yes, I am now using partialize to handle it