@cripty2001/utils 0.0.81 → 0.0.83
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/react-whispr.js +27 -17
- package/package.json +1 -1
package/dist/react-whispr.js
CHANGED
|
@@ -104,23 +104,33 @@ function useSynced(def, value, setValue) {
|
|
|
104
104
|
if ((value !== undefined && setValue === undefined) ||
|
|
105
105
|
(value === undefined && setValue !== undefined))
|
|
106
106
|
throw new Error('Either value and setValue must be provided, or both must be undefined');
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(0,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
const setValueRef = (0, react_1.useRef)(setValue);
|
|
108
|
+
(0, react_1.useEffect)(() => {
|
|
109
|
+
setValueRef.current = setValue;
|
|
110
|
+
}, [setValue]);
|
|
111
|
+
// Only sync downstream (external -> local)
|
|
112
|
+
(0, react_1.useEffect)(() => {
|
|
113
|
+
if (value === undefined)
|
|
114
|
+
return;
|
|
115
|
+
if ((0, lodash_1.isEqual)(v, value))
|
|
116
|
+
return;
|
|
117
|
+
console.log('SYNC DOWNSTREAM', value);
|
|
118
|
+
setV(value);
|
|
119
|
+
}, [value]);
|
|
120
|
+
// Return a setter that updates both
|
|
121
|
+
const syncedSetter = (0, react_1.useCallback)((newValue) => {
|
|
122
|
+
setV(prev => {
|
|
123
|
+
const resolved = typeof newValue === 'function'
|
|
124
|
+
? newValue(prev)
|
|
125
|
+
: newValue;
|
|
126
|
+
// Update external immediately if available
|
|
127
|
+
if (setValueRef.current) {
|
|
128
|
+
setValueRef.current(resolved);
|
|
129
|
+
}
|
|
130
|
+
return resolved;
|
|
131
|
+
});
|
|
132
|
+
}, []);
|
|
133
|
+
return [v, syncedSetter];
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
*
|
package/package.json
CHANGED