Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,26 @@ For a full list of middleware, see [zustand middleware](https://www.npmjs.com/pa
import { persist } from 'zustand/middleware';

const useStoreWithUndo = create<StoreState>()(
temporal(
(set) => ({
// your store fields
}),
{
wrapTemporal: (storeInitializer) =>
persist(storeInitializer, { name: 'temporal-persist' }),
},
),
persist( // <-- persist
temporal(
(set) => ({
// your store fields
}),
{
wrapTemporal: (storeInitializer) => {
persist(storeInitializer, { // <-- persist
name: 'temporal-persist'
});
},
}
)
)
);
```

> In the example above, note that we use `persist` twice. The outer persist is persisting your user facing store, and the inner persist, as part of the temporal options, will persist the temporal store that's created by the middleware. Simply put: there are two zustand stores, so you must persist both.


### `useStore.temporal`

When using zustand with the `temporal` middleware, a `temporal` object is attached to your vanilla or React-based store. `temporal` is a vanilla zustand store: see [StoreApi<T> from](https://github.com/pmndrs/zustand/blob/f0ff30f7c431f6bf25b3cb439d065a7e61355df4/src/vanilla.ts#L8) zustand for more details.
Expand Down
Loading