How does persist middleware work with URL and how to test it? #2038
Replies: 3 comments 2 replies
-
removeItem is called when clearStorage is called explicitly: zustand/src/middleware/persist.ts Lines 346 to 348 in 266e864 I've never tried it, so can't help much. |
Beta Was this translation helpful? Give feedback.
-
The example is pretty clear about how works. The persist middleware works on any kind of storage (that can persist data). In this case we can use the So we can test it, actually is pretty easy. Let's say that we have the next query string or search parameters (window.location.search)
We can parse them with
If we delete So the best way to test it out is by checking |
Beta Was this translation helpful? Give feedback.
-
Hi! Great way to persist the state to the URL. Thx for that. I have a question related to this. I'm using it in the context of a Next.js application. It supports changing the search parameters when using I hope my description was clear. Thank you! |
Beta Was this translation helpful? Give feedback.
-
On this page 'Connect to state with URL': https://docs.pmnd.rs/zustand/guides/connect-to-state-with-url-hash. It shows a nice example of how to use persist middleware to store info within the URL. However, it does not describe how it works, especially I am confused about when
removeItem
would be triggered and how to test it. It would be nice if someone could provide me with some explanation or show me some code examples.Beta Was this translation helpful? Give feedback.
All reactions