Skip to content

Commit 6b8d232

Browse files
authored
add: manual checkpoints (#36)
* add: manual checkpoints * add: test points and readme updated * Update README.md
1 parent 7643f9d commit 6b8d232

File tree

3 files changed

+468
-54
lines changed

3 files changed

+468
-54
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,58 @@ const App = () => {
6363
};
6464
```
6565

66+
## Manual Checkpoints
67+
68+
Manual checkpoints are helpful also when you want manual control over checkpoints. For example it is more helpful when you want to handle input type html tag where value needs to be handled alongside the undo and redo functionality should be handled over some conditions.
69+
70+
```js
71+
import React from 'react';
72+
import ReactDOM from 'react-dom';
73+
import useUndo from 'use-undo';
74+
75+
const App = () => {
76+
const [
77+
countState,
78+
{
79+
set: setCount,
80+
reset: resetCount,
81+
undo: undoCount,
82+
redo: redoCount,
83+
canUndo,
84+
canRedo,
85+
},
86+
] = useUndo(0, { useCheckpoints: true });
87+
const { present: presentCount } = countState;
88+
89+
return (
90+
<div>
91+
<p>You clicked {presentCount} times</p>
92+
<button key="increment" onClick={() => setCount(presentCount + 1, true)}>
93+
WithCheckpoint+
94+
</button>
95+
<button key="decrement" onClick={() => setCount(presentCount - 1, true)}>
96+
WithCheckpoint-
97+
</button>
98+
<button key="increment" onClick={() => setCount(presentCount + 1)}>
99+
NoCheckpoint+
100+
</button>
101+
<button key="decrement" onClick={() => setCount(presentCount - 1)}>
102+
NoCheckpoint-
103+
</button>
104+
<button key="undo" onClick={undoCount} disabled={!canUndo}>
105+
undo
106+
</button>
107+
<button key="redo" onClick={redoCount} disabled={!canRedo}>
108+
redo
109+
</button>
110+
<button key="reset" onClick={() => resetCount(0)}>
111+
reset to 0
112+
</button>
113+
</div>
114+
);
115+
};
116+
```
117+
66118
## API
67119

68120
### useUndo

0 commit comments

Comments
 (0)