Persist does not seem to work with Set - Uncaught TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) #2452
Replies: 2 comments 2 replies
-
### UPDATE: I converted the store to use an array instead of a Set:
Now I am getting another error when adding a favourite:
Console.log: Without persist:
With persist:
|
Beta Was this translation helpful? Give feedback.
-
@dbritto-dev, in my opinion, the documentation for Persist is not clearly organized and complete. I have had, of course, done multiple searches and studied this for two hours, and that section did not come up in any of those searches. I saw that section at the bottom after reading the whole page from top to bottom. The Map example at the bottom did not work for me. I managed to put together a solution for Set based on superjson, which seems to work:
|
Beta Was this translation helpful? Give feedback.
-
Hi
I created a Zustand store based on Set to keep a selection of favourite items, which works perfectly OK:
However, when I add persistance with persist, it does not seem to work:
I am getting this error:
Interestingly, when I do console.log of the store favourites variable in a React FC that uses it, I get a different type, depending on whether persist is used or not:
Without persist:
With persist:
It looks as if persist is initializing favourites as an empty Object, rather than an empty Set.
Object is not iterable and we seem to need an iterable.
Beta Was this translation helpful? Give feedback.
All reactions