Skip to content

Commit 1bdb541

Browse files
committed
docs(readme): update
1 parent db25138 commit 1bdb541

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)