diff --git a/README.md b/README.md
index 3da77e5..376c890 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,57 @@
# use-travel
+
A React hook for state time travel with undo, redo, and reset functionalities.
-TODO
+### Installation
+
+```bash
+npm install use-travel mutative
+# or
+yarn add use-travel mutative
+```
+
+### Features
+
+- Undo/Redo/Reset
+- Small size for time travel with Patches history
+- Customizable history size
+- Customizable initial patches
+- High performance
+- Mark function for custom immutability
+
+### TODO
+
+- [ ] add `archive` functionality
+
+### API
+
+```jsx
+import { useTravel } from 'use-travel';
+
+const App = () => {
+ const [state, setState, controls]} = useTravel(0, {
+ maxHistory: 10,
+ initialPatches: [],
+ });
+ return (
+
+
{state}
+
+
+
+
+
+ {controls.getHistory().map((state, index) => (
+
{state}
+ ))}
+ {controls.patches.map((patch, index) => (
+
{patch}
+ ))}
+
{controls.position}
+
+
+ );
+}
+```
diff --git a/package.json b/package.json
index d73417b..1d16829 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "use-travel",
- "version": "0.0.1",
+ "version": "0.1.0",
"description": "A React hook for state time travel with undo, redo, and reset functionalities.",
"main": "dist/index.cjs.js",
"unpkg": "dist/index.umd.js",
@@ -43,8 +43,10 @@
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.2",
+ "@testing-library/react": "^14.2.1",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.5",
+ "@types/react": "^18.2.66",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"commitizen": "^4.3.0",
@@ -57,6 +59,8 @@
"jest-environment-jsdom": "^29.5.0",
"mutative": "^1.0.3",
"prettier": "^2.8.6",
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0",
"rimraf": "^4.4.0",
"rollup": "^3.20.0",
"rollup-plugin-terser": "^7.0.0",
@@ -81,6 +85,11 @@
}
},
"peerDependencies": {
- "mutative": "^1.0.3"
+ "@types/react": "^18.0 || ^17.0",
+ "mutative": "^1.0.3",
+ "react": "^18.0 || ^17.0"
+ },
+ "dependencies": {
+ "use-mutative": "^1.0.0"
}
}
diff --git a/src/index.ts b/src/index.ts
index a613b6b..cee2afe 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,3 +1,209 @@
-export const useTravel = (state: any) => {
- //
+import { useCallback, useEffect, useMemo } from 'react';
+import {
+ type Options as MutativeOptions,
+ type Patches,
+ type Draft,
+ type Immutable,
+ apply,
+ rawReturn,
+} from 'mutative';
+import { useMutative } from 'use-mutative';
+
+type TravelPatches = {
+ patches: Patches[];
+ inversePatches: Patches[];
+};
+
+type Options