use-synchronized-state 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/README.md +1 -3
- package/package.json +2 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.mjs +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -168,9 +168,7 @@ function ChildComponent({ parentState }: { parentState: number }) {
|
|
|
168
168
|
}
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
The 'use-synchronized-state' hook
|
|
172
|
-
if the reactive value changes (for example setParentState(1) is called), both parentState and syncState will have
|
|
173
|
-
the same value from the first render (after the setParentState). There will still be two renders, but the values will be in sync from the first one.
|
|
171
|
+
The 'use-synchronized-state' hook solves the synchronization problem in an easier and more consistent manner.
|
|
174
172
|
Also, the api is easy to use and it works for any reactive value.
|
|
175
173
|
|
|
176
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-synchronized-state",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "A React hook that creates a synchronized state with a reactive value (fixing the Cascading updates issue)",
|
|
5
5
|
"homepage": "https://github.com/rhorge/use-synchronized-state#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"start": "rollup -c -w",
|
|
31
31
|
"test": "jest"
|
|
32
32
|
},
|
|
33
|
+
"sideEffects": false,
|
|
33
34
|
"jest": {
|
|
34
35
|
"transform": {
|
|
35
36
|
".(ts|tsx)": "ts-jest"
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var react=require("react");function useSyncState(e){var t=react.useState(e),a=t[0],t=t[1],r=react.useState(e),c=r[0],r=r[1];return a!==e&&(t(c=e),r(e)),[c,r]}exports.useSyncState=useSyncState;
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* This hook creates a synchronized state while avoiding the cascading update issue.
|
|
4
|
-
* In our case, synchronized means that when there is a change in propsState,
|
|
5
|
-
* the returned state changes to the same value,
|
|
6
|
-
* but it can also change independently when the returned setState is called.
|
|
7
|
-
* @param propsState - a reactive value (e.g. state, props) with which our returned state will synchronize
|
|
8
|
-
* @return the exact same output as useState: [state, setState], where state is the synchronized state with the propsState
|
|
9
|
-
*/
|
|
10
|
-
export declare function useSyncState<T>(propsState: T): [T, Dispatch<SetStateAction<T>>];
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useState}from"react";function useSyncState(t){var e=useState(t),a=e[0],e=e[1],r=useState(t),u=r[0],r=r[1];return a!==t&&(e(u=t),r(t)),[u,r]}export{useSyncState};
|