@purr-core/hooks.sync-state-with-props 0.0.8 → 0.0.9
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/dist/index.cjs +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react');var l=(t,e=false)=>{let[r,u]=react.useState(t),V=react.useCallback(a=>{e&&u(a);},[e]);return {currentValue:e?r:t,setCurrentValue:V}},o=l;module.exports=o;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The return type of the useSyncStateWithProps hook.
|
|
3
|
+
*
|
|
4
|
+
* @interface ISyncStateWithPropsReturnType<V>
|
|
5
|
+
* @property {V} currentValue - The current value.
|
|
6
|
+
* @property {function} setCurrentValue - The function to set the current value.
|
|
7
|
+
*/
|
|
8
|
+
interface ISyncStateWithPropsReturnType<V> {
|
|
9
|
+
currentValue: V;
|
|
10
|
+
setCurrentValue: (value: V) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A hook that syncs the value with the props.
|
|
14
|
+
*
|
|
15
|
+
* @param {V} value - The value to sync.
|
|
16
|
+
* @param {boolean} [isStandalone=false] - Whether the value is standalone.
|
|
17
|
+
* @returns {ISyncStateWithPropsReturnType<V>} The return value of the hook.
|
|
18
|
+
*/
|
|
19
|
+
declare const useSyncStateWithProps: <V>(value: V, isStandalone?: boolean) => ISyncStateWithPropsReturnType<V>;
|
|
20
|
+
|
|
21
|
+
export { useSyncStateWithProps as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The return type of the useSyncStateWithProps hook.
|
|
3
|
+
*
|
|
4
|
+
* @interface ISyncStateWithPropsReturnType<V>
|
|
5
|
+
* @property {V} currentValue - The current value.
|
|
6
|
+
* @property {function} setCurrentValue - The function to set the current value.
|
|
7
|
+
*/
|
|
8
|
+
interface ISyncStateWithPropsReturnType<V> {
|
|
9
|
+
currentValue: V;
|
|
10
|
+
setCurrentValue: (value: V) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A hook that syncs the value with the props.
|
|
14
|
+
*
|
|
15
|
+
* @param {V} value - The value to sync.
|
|
16
|
+
* @param {boolean} [isStandalone=false] - Whether the value is standalone.
|
|
17
|
+
* @returns {ISyncStateWithPropsReturnType<V>} The return value of the hook.
|
|
18
|
+
*/
|
|
19
|
+
declare const useSyncStateWithProps: <V>(value: V, isStandalone?: boolean) => ISyncStateWithPropsReturnType<V>;
|
|
20
|
+
|
|
21
|
+
export { useSyncStateWithProps as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {useState,useCallback}from'react';var l=(t,e=false)=>{let[r,u]=useState(t),V=useCallback(a=>{e&&u(a);},[e]);return {currentValue:e?r:t,setCurrentValue:V}},o=l;export{o as default};
|