0.1.0 • Published 11 months ago
zustand-querystring v0.1.0
zustand-querystring
A Zustand middleware that syncs the store with the querystring.
Try on StackBlitz (You need to click "Open in New Tab")
Examples:
Quickstart:
import create from 'zustand';
import { querystring } from 'zustand-querystring';
interface Store {
count: number;
ticks: number;
someNestedState: {
nestedCount: number;
hello: string;
};
}
export const useStore = create<Store>()(
querystring(
(set, get) => ({
count: 0,
ticks: 0,
someNestedState: {
nestedCount: 0,
hello: 'Hello',
},
}),
{
// select controls what part of the state is synced with the query string
// pathname is the current route (e.g. /about or /)
select(pathname) {
return {
count: true,
// ticks: false, <- false by default
someNestedState: {
nestedCount: true,
hello: '/about' === pathname,
},
// OR select the whole nested state
// someNestedState: true
};
},
},
),
);
querystring options:
- select - the select option controls what part of the state is synced with the query string
- key: string - the key option controls how the state is stored in the querystring (default: $)
- url - the url option is used to provide the request url on the server side render
0.0.20-beta.0
1 year ago
0.1.0
11 months ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.17
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.11
2 years ago
0.0.12
2 years ago
0.0.13
2 years ago
0.0.14
2 years ago
0.0.10
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago