You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,6 +117,47 @@ const App = () => {
117
117
|`controls.go`| (nextPosition: number) => void | Go to the specific position of the state |
118
118
|`controls.archive`| () => void | Archive the current state(the `autoArchive` options should be `false`) |
119
119
120
+
### useTravelStore
121
+
122
+
When you need to manage a single `Travels` instance outside of React—e.g. to share the same undo/redo history across multiple components—create the store manually and bind it with `useTravelStore`. The hook keeps React in sync with the external store, exposes the same controls object, and rejects mutable stores to ensure React can observe updates.
123
+
124
+
```tsx
125
+
// store.ts
126
+
import { Travels } from'travels';
127
+
128
+
exportconst travels =newTravels({ count: 0 }); // mutable: true is not supported
`useTravelStore` stays reactive even when the `Travels` instance is updated elsewhere (for example, in services or other components) and forwards manual archive helpers when the store is created with `autoArchive: false`.
160
+
120
161
### Archive Mode
121
162
122
163
`use-travel` provides two archive modes to control how state changes are recorded in history:
0 commit comments