This middleware does a few interesting things:
- Ensures a
url
shape in the zustand store, where we'll store URL information. - Assumes we will be storing our
url
state slice in the?state
search parameter after it has been stringified and base 64 encoded. - On creation, decodes stores state from the
?state
search parameter into theurl
slice of our store. - After each state update, updates the
?state
search parameter with the newurl
state slice. - Sets up an event listener that listens for
popstate
and re-decodes the state from the URL into our store.
Neato.