From 165a551af93a7a1546cb350700855dd41f8d0632 Mon Sep 17 00:00:00 2001 From: unadlib Date: Fri, 22 Mar 2024 02:27:27 +0800 Subject: [PATCH] fix(update): fix update value --- README.md | 14 ++++++++------ package.json | 2 +- src/index.ts | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e8615a3..4534791 100644 --- a/README.md +++ b/README.md @@ -31,30 +31,33 @@ yarn add use-travel mutative 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 +```jsx import { useTravel } from 'use-travel'; const App = () => { const [state, setState, controls] = useTravel(0, { maxHistory: 10, - initialPatches: [], + initialPatches: { + patches: [], + inversePatches: [], + }, }); return (
{state}
- - {controls.getHistory().map((state, index) => (
{state}
))} - {controls.patches.map((patch, index) => ( + {controls.patches.patches.map((patch, index) => (
{patch}
))}
{controls.position}
@@ -70,7 +73,6 @@ const App = () => { }; ``` - ### Options | Options | type | description | default | diff --git a/package.json b/package.json index b46fd29..a814a6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "use-travel", - "version": "0.2.0", + "version": "0.2.1", "description": "A React hook for state time travel with undo, redo, and reset functionalities.", "main": "dist/index.cjs.js", "unpkg": "dist/index.umd.js", diff --git a/src/index.ts b/src/index.ts index e9d0f25..a9abdaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -99,7 +99,7 @@ export const useTravel = ( setState(nextState); setPosition(position + 1); setAllPatches((_allPatches) => { - const notLast = position < allPatches.patches.length; + const notLast = position < _allPatches.patches.length; // Remove all patches after the current position if (notLast) { _allPatches.patches.splice(