@cripty2001/utils 0.0.78 → 0.0.80

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.
@@ -49,7 +49,7 @@ export declare function useDebounced<T>(value: T): T;
49
49
  * @param setValue The function to set the value
50
50
  * @returns The synced value and the function to set it
51
51
  */
52
- export declare function useSynced<T extends any>(def: T, handlers?: [T, (value: T) => void]): [T, React.Dispatch<React.SetStateAction<T>>];
52
+ export declare function useSynced<T extends any>(def: T, value: T | undefined, setValue: ((value: T) => void) | undefined): [T, React.Dispatch<React.SetStateAction<T>>];
53
53
  /**
54
54
  *
55
55
  * Wraps an async function into a reactable data.
@@ -99,18 +99,24 @@ function useDebounced(value) {
99
99
  * @param setValue The function to set the value
100
100
  * @returns The synced value and the function to set it
101
101
  */
102
- function useSynced(def, handlers) {
102
+ function useSynced(def, value, setValue) {
103
103
  const [v, setV] = (0, react_1.useState)(def);
104
- if (handlers !== undefined) {
105
- const [value, setValue] = handlers;
104
+ if ((value !== undefined && setValue === undefined) ||
105
+ (value === undefined && setValue !== undefined))
106
+ throw new Error('Either value and setValue must be provided, or both must be undefined');
107
+ if (value !== undefined && setValue !== undefined) {
106
108
  (0, react_1.useEffect)(() => {
109
+ console.log('syncing value downstream', value, '->', v);
107
110
  if ((0, lodash_1.isEqual)(v, value))
108
111
  return;
112
+ console.log("SYNCED");
109
113
  setV(value);
110
114
  }, [value, v, setV]);
111
115
  (0, react_1.useEffect)(() => {
116
+ console.log('syncing value upstream', v, '->', value);
112
117
  if ((0, lodash_1.isEqual)(v, value))
113
118
  return;
119
+ console.log("SYNCED");
114
120
  setValue(v);
115
121
  }, [v, value, setValue]);
116
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {