use-synchronized-state 1.0.15 → 1.0.16

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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.16 (Jan 23, 2026)
2
+ - Make the hook compatible with the Fiber algorithm
3
+
1
4
  ## 1.0.15 (Jan 8, 2026)
2
5
  - Correct links in package.json
3
6
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # A React hook that creates a synchronized state with a reactive value in react (fixing the Cascading updates issue)
1
+ # A React hook that creates a synchronized state with a reactive value (fixing the Cascading updates issue)
2
2
 
3
3
  ## Highlights
4
4
  - Offers a hook called useSyncState
@@ -149,9 +149,10 @@ This is the cascading updates problem in all its glory, instead of having one re
149
149
 
150
150
  What react docs tell us to do in this case can be found here
151
151
  https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes.
152
- I have changed the above example to match it. It still rerenders the ChildComponent twice, which still causes a
152
+ The above example was changed to match the docs. It still rerenders the ChildComponent twice, which still causes a smaller
153
153
  performance penalty, is hard to reason about and works only for states defined in the same component
154
- (if syncState was a prop, it wouldn't work).
154
+ (if syncState was a prop, it wouldn't work). Also, the parentState and syncState will be synchronized only starting with
155
+ the second render.
155
156
 
156
157
  ```typescript jsx
157
158
  function ChildComponent({ parentState }: { parentState: number }) {
@@ -167,9 +168,10 @@ function ChildComponent({ parentState }: { parentState: number }) {
167
168
  }
168
169
  ```
169
170
 
170
- The 'use-synchronized-state' hook fixes all these issues by synchronizing the values in the same and only render. In the bellow example,
171
+ The 'use-synchronized-state' hook fixes some of these issues by synchronizing the values in an easier and more consistent manner. In the bellow example,
171
172
  if the reactive value changes (for example setParentState(1) is called), both parentState and syncState will have
172
- the same value from the first render (after the setParentState) and there will be no additional render (only the needed one).
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.
174
+ Also, the api is easy to use and it works for any reactive value.
173
175
 
174
176
 
175
177
  ```typescript jsx
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- var react=require("react");function useSyncState(e){var t=react.useState(!0)[1],c=react.useRef(e),r=react.useRef(e),r=(r.current!==e&&(r.current=e,c.current=e),react.useCallback(function(e){var r=c.current;c.current=e instanceof Function?e(c.current):e,t(function(e){return r!==c.current?!e:e})},[c]));return[c.current,r]}exports.useSyncState=useSyncState;
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 CHANGED
@@ -5,6 +5,6 @@ import { Dispatch, SetStateAction } from 'react';
5
5
  * the returned state changes to the same value,
6
6
  * but it can also change independently when the returned setState is called.
7
7
  * @param propsState - a reactive value (e.g. state, props) with which our returned state will synchronize
8
- * Returns the exact same output as useState: [state, setState], where state is the synchronized state with the propsState
8
+ * @return the exact same output as useState: [state, setState], where state is the synchronized state with the propsState
9
9
  */
10
10
  export declare function useSyncState<T>(propsState: T): [T, Dispatch<SetStateAction<T>>];
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useState,useRef,useCallback}from"react";function useSyncState(e){var t=useState(!0)[1],u=useRef(e),r=useRef(e),r=(r.current!==e&&(r.current=e,u.current=e),useCallback(function(e){var r=u.current;u.current=e instanceof Function?e(u.current):e,t(function(e){return r!==u.current?!e:e})},[u]));return[u.current,r]}export{useSyncState};
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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "use-synchronized-state",
3
- "version": "1.0.15",
4
- "description": "A React hook that creates a synchronized state with a reactive value in react (fixing the Cascading updates issue)",
3
+ "version": "1.0.16",
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": {
7
7
  "url": "https://github.com/rhorge/use-synchronized-state/issues"