Skip to content

Commit

Permalink
docs(readme): update
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Mar 18, 2024
1 parent 56284dd commit 7fc9db4
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> | 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';
Expand Down Expand Up @@ -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<T> | 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
Expand Down

0 comments on commit 7fc9db4

Please sign in to comment.