File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,6 +273,45 @@ const useTodoStore = create<State & Actions>()(
273273);
274274` ` `
275275
276+ zustand-travel with other zustand middleware:
277+
278+ ` ` ` ts
279+ import { create } from " zustand" ;
280+ import { travel } from " zustand-travel" ;
281+ import { persist } from " zustand/middleware" ;
282+
283+ type State = {
284+ count: number ;
285+ };
286+
287+ type Actions = {
288+ increment : (qty : number ) => void ;
289+ decrement : (qty : number ) => void ;
290+ };
291+
292+ export const useCountStore = create <State & Actions >()(
293+ travel (
294+ persist (
295+ (set ) => ({
296+ count: 0 ,
297+ increment : (qty : number ) =>
298+ set ((state ) => {
299+ state .count += qty ;
300+ }),
301+ decrement : (qty : number ) =>
302+ set ((state ) => {
303+ state .count -= qty ;
304+ }),
305+ }),
306+ {
307+ name: " counter" ,
308+ }
309+ )
310+ )
311+ );
312+ ` ` `
313+
314+
276315### Using Controls in React
277316
278317` ` ` tsx
You can’t perform that action at this time.
0 commit comments