Skip to content

Commit ac724e7

Browse files
rootroot
authored andcommitted
[ADD] useStateHistoryGetter
1 parent 4120b27 commit ac724e7

6 files changed

Lines changed: 41 additions & 2 deletions

File tree

apps/react-tools-demo/src/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ blockquote>ul>li>strong {
328328
.features-container {
329329
grid-template-columns: repeat(1, 1fr);
330330
}
331+
}
331332

332333
@media screen and (max-width: 1190px) {
333334
.open-nav {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The implementation is like that useStateHistory, adding useStateGetter getter function.
2+
3+
Please visit [useStateHistory](/useStateHistory) and [useStateGetter](/useStateGetter) examples to see how it works.

apps/react-tools-demo/src/constants/components.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const COMPONENTS = [
33
"usePrevious",
44
"useStateGetter",
55
"useStateHistory",
6+
"useStateHistoryGetter",
67
"useMemoCompare",
78
"useMemoDeepCompare",
89
"useCallbackCompare",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# useStateHistoryGetter
2+
Custom useState with getter state function and that tracks and allows to use previous values.
3+
4+
## Usage
5+
6+
The implementation is like that useStateHistory, adding useStateGetter getter function.
7+
8+
Please visit [useStateHistory](/useStateHistory) and [useStateGetter](/useStateGetter) examples to see how it works.
9+
10+
## API
11+
12+
```tsx
13+
useStateHistoryGetter <T>(initialState: T | (() => T), capacity: number | "no-limit" = "no-limit"): [T, Dispatch<SetStateAction<T>>, () => T, ReturnType<typeof useStateHistory<T>>[2]]
14+
```
15+
16+
> ### Params
17+
>
18+
> - __initialState__: _T | () => T_
19+
value or a function.
20+
> - __capacity="no-limit"__: _number | "no-limit"_
21+
history capacity (default 'no-limit').
22+
>
23+
24+
> ### Returns
25+
>
26+
> - __array__: _[T, Dispatch<SetStateAction<T>>, getter: () => T, history: {history: readonly T[], presentPointer: number, trackUpdate: (enable:boolean) => void, canUndo: boolean, canRedo: boolean, undo: () => void, redo: () => void, go: (index: number) => void, clear: (value?: T) => void}]_
27+
>

apps/react-tools-demo/src/router/Router.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import HomeWrapper from '../components/home/HomeWrapper';
66
import usePreviousMD from '../markdown/UsePrevious.md?url';
77
import useStateGetterMD from '../markdown/UseStateGetter.md?url';
88
import useStateHistoryMD from '../markdown/UseStateHistory.md?url';
9+
import useStateHistoryGetterMD from '../markdown/useStateHistoryGetter.md?url';
910
import useCallbackCompareMD from '../markdown/UseCallbackCompare.md?url';
1011
import useCallbackDeepCompareMD from '../markdown/UseCallbackDeepCompare.md?url';
1112
import useMemoCompareMD from '../markdown/UseMemoCompare.md?url';
@@ -59,6 +60,12 @@ function Router() {
5960
markdown={useStateHistoryMD}
6061
/>
6162
},
63+
{
64+
path: "/useStateHistoryGetter",
65+
element: <MarkdownLayout
66+
source={useStateHistoryGetterMD}
67+
/>
68+
},
6269
{
6370
path: "/useCallbackCompare",
6471
element: <ComponentLayout

packages/react-tools/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# TODO
22
- __STATE__
33
- [x] usePrevious
4-
- [-] useStateGetter
4+
- [x] useStateGetter
55
- [ ] useStateRestore
66
- [x] useStateHistory
7-
- [-] useStateHistoryGetter
7+
- [x] useStateHistoryGetter
88
- [ ] useReducerHistory
99
- [ ] useReducerGetter
1010
- [ ] useReducerRestore

0 commit comments

Comments
 (0)