Skip to content

Commit cb16706

Browse files
committed
[ADD] useProxyState hook docs
1 parent d4f3b73 commit cb16706

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

apps/react-tools-demo/src/components/hooks/useProxyState/UseProxyState.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { memo, useCallback } from "react";
22
import { useProxyState } from "../../../../../../packages/react-tools/src";
33

44
/**
5-
DEMO
5+
The component has:
6+
- a state created with _useProxyStore_, that is a object with _num_ property, a number, and _nested_ property that is a object with _random_ property that is a string.
7+
- a useCallback function _increment_ that increment _num_ property.
8+
- a useCallback function _random_ that generate random number, assigned to _nested.random_ property.
9+
- a _Child1_ component that receives _num_ and _increment_ as props.
10+
- a _Child2_ component that receives _nested.random_ and _random_ as props.
611
*/
712
const Child1 = memo(({ state, onClick }: { state: number, onClick: ()=>void }) => {
813
return (<>

apps/react-tools-demo/src/markdown/useLocalStorageState.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Custom _useState_ hook implementation using _LocalStorage_, with immutable _gett
44
## Usage
55

66
```tsx
7-
const Child = () => {
7+
const Child = memo(() => {
88
const [state] = useLocalStorageState<string>({key:"demo", opts: {mode: "read"}});
99
return (<>
1010
<h3>Child component 1</h3>
1111
<p>State is {state}</p>
1212
</>)
13-
}
13+
})
1414

15-
const Child2 = () => {
15+
const Child2 = memo(() => {
1616
const [setState] = useLocalStorageState<string>({key:"demo", opts: {mode: "write"}});
1717
return (<>
1818
<h3>Child component 2</h3>
@@ -23,7 +23,7 @@ const Child2 = () => {
2323
<input type="text" />
2424
</form>
2525
</>)
26-
}
26+
})
2727

2828
const UseLocalStorageState = () => {
2929
const [, , , remove] = useLocalStorageState({ key: "demo", initialState: "prova" });

apps/react-tools-demo/src/markdown/useProxyState.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# useProxyState
2-
Hook to handle component state that allows you to use an object for your state and mutating it in a way more idiomatic for JS.
2+
Hook to handle component state that allows you to use an object for your state and mutating it in a way more idiomatic for JS. __N.B.__
33

44
## Usage
55

@@ -40,7 +40,12 @@ UseProxyState.displayName = "UseProxyState";
4040
export { UseProxyState };
4141
```
4242

43-
> DEMO
43+
> The component has:
44+
> - a state created with _useProxyStore_, that is a object with _num_ property, a number, and _nested_ property that is a object with _random_ property that is a string.
45+
> - a useCallback function _increment_ that increment _num_ property.
46+
> - a useCallback function _random_ that generate random number, assigned to _nested.random_ property.
47+
> - a _Child1_ component that receives _num_ and _increment_ as props.
48+
> - a _Child2_ component that receives _nested.random_ and _random_ as props.
4449
4550

4651
## API

packages/react-tools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- [x] useMap
1313
- [x] useSet
1414
- [x] useArray
15-
- [-] useProxyState (manca docs)
15+
- [x] useProxyState
1616
- [ ] useProxyStore
1717
- [ ] createProxyStore
1818
- __EFFECTS__

packages/react-tools/src/hooks/useProxyState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useReducer, useRef } from "react"
22

33
/**
4-
* __`useProxyState`__: Hook to handle component state that allows you to use an object for your state and mutating it in a way more idiomatic for JS.
4+
* __`useProxyState`__: Hook to handle component state that allows you to use an object for your state and mutating it in a way more idiomatic for JS. __N.B.__: not destructure state, otherwise break changes updated.
55
* @param {T | () => T} initialState - value or function
66
* @param {boolean} [proxyInDepth=false] - if true, it creates proxy for nested object also.
77
* @returns {T} state

0 commit comments

Comments
 (0)