diff --git a/README.md b/README.md index 9561fec..e132ee4 100644 --- a/README.md +++ b/README.md @@ -25,28 +25,7 @@ yarn add use-travel mutative ### API -### Options - -| Options | type | description | default | -| ---------------- | ------------- | ------------------------------------- | -------------------------------- | -| `maxHistory` | number | The maximum number of history to keep | 10 | -| `initialPatches` | TravelPatches | The initial patches | {patches: [],inversePatches: []} | - -### Return - -| Return | type | description | -| --------------------- | -------------------------- | ------------------------------------------------------------------ | -| `state` | T | The current state | -| `setState` | Dispatch | The state setter, support mutation update or return immutable data | -| `controls.back` | () => void | Go back to the previous state | -| `controls.forward` | () => void | Go forward to the next state | -| `controls.reset` | () => void | Reset the state to the initial state | -| `controls.canUndo` | () => boolean | Check if can go back to the previous state | -| `controls.canRedo` | () => boolean | Check if can go forward to the next state | -| `controls.getHistory` | () => T[] | Get the history of the state | -| `controls.patches` | TravelPatches[] | Get the patches history of the state | -| `controls.position` | number | Get the current position of the state | -| `controls.go` | (position: number) => void | Go to the specific position of the state | +You can use `useTravel` to create a time travel state. And it returns a tuple with the current state, the state setter, and the controls. The controls include `back`, `forward`, `reset`, `canUndo`, `canRedo`, `getHistory`, `patches`, `position`, and `go`. ```tsx import { useTravel } from 'use-travel'; @@ -87,6 +66,30 @@ const App = () => { }; ``` + +### Options + +| Options | type | description | default | +| ---------------- | ------------- | ------------------------------------- | -------------------------------- | +| `maxHistory` | number | The maximum number of history to keep | 10 | +| `initialPatches` | TravelPatches | The initial patches | {patches: [],inversePatches: []} | + +### Return + +| Return | type | description | +| --------------------- | -------------------------- | ------------------------------------------------------------------ | +| `state` | T | The current state | +| `setState` | Dispatch | The state setter, support mutation update or return immutable data | +| `controls.back` | () => void | Go back to the previous state | +| `controls.forward` | () => void | Go forward to the next state | +| `controls.reset` | () => void | Reset the state to the initial state | +| `controls.canUndo` | () => boolean | Check if can go back to the previous state | +| `controls.canRedo` | () => boolean | Check if can go forward to the next state | +| `controls.getHistory` | () => T[] | Get the history of the state | +| `controls.patches` | TravelPatches[] | Get the patches history of the state | +| `controls.position` | number | Get the current position of the state | +| `controls.go` | (position: number) => void | Go to the specific position of the state | + ### TODO - [ ] add `archive` functionality