zustand-querystring is a middleware for Zustand that provides declarative synchronization between parts of a Zustand store's state and the URL's query string. This enables persistent and shareable application states directly embedded in the browser's URL. The current stable version is 0.7.0, with ongoing development evidenced by recent frequent releases that include bug fixes and new features. Key differentiators include flexible state selection via the `select` option, support for multiple serialization formats (e.g., `plain`, `readable`, or custom), granular control over how `null` and `undefined` values are handled (`syncNull`, `syncUndefined`), and a powerful bidirectional `map` option for complex transformations between store state and URL representation. It supports both individual query parameters for each state key (`key: false`) or consolidating the entire state into a single query parameter, and offers prefixing for managing multiple stores on the same page.
npm install zustand-querystringVerified import paths — ran on the pinned version, not inferred.
Initializes a Zustand store with the querystring middleware, syncing `search` and `page` state to URL parameters.
Re-evaluate how existing URLs are generated and parsed, potentially requiring a one-time migration or handling of legacy URLs if backward compatibility is critical. Ensure all new URLs are encoded with `encodeURIComponent`.
Update existing 'readable' format URLs or migrate to the newer 'plain' format introduced in v0.5.0, which offers a cleaner, hand-editable URL structure and is generally recommended.
If you need `null` or `undefined` to be explicitly synchronized to the URL (e.g., as part of a filter state), set the `syncNull: true` or `syncUndefined: true` options in the middleware configuration.
Upgrade to version 0.6.0 or higher. If upgrading is not immediately possible, consider custom mapping or alternative serialization for array types to ensure correct parsing.
Decide on a consistent `key` strategy early in development. If you must change it on a live application, implement a migration strategy (e.g., redirecting old URLs, providing a backward-compatible parser) to prevent broken links.
Upgrade `zustand-querystring` to version 0.6.0 or higher, which includes a fix for this parsing issue.
This issue was fixed in version 0.3.1. Ensure you are using `zustand-querystring` version 0.3.1 or later.
Verify that your `select` function correctly returns `true` for all state fields you intend to sync. Also, check the `key` option: `key: false` uses individual parameters, while `key: 'state'` (or any string) consolidates state into a single parameter named 'state' (or your chosen string).
To synchronize `null` or `undefined` values, set `syncNull: true` or `syncUndefined: true` (or both) in the middleware options: `{ syncNull: true, syncUndefined: true }`.