@cripty2001/utils 0.0.76 → 0.0.77

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, value: T | undefined, setValue: ((value: T) => void) | undefined): [T, React.Dispatch<React.SetStateAction<T>>];
52
+ export declare function useSynced<T extends any>(def: T, handlers: [T, (value: T) => void]): [T, React.Dispatch<React.SetStateAction<T>>];
53
53
  /**
54
54
  *
55
55
  * Wraps an async function into a reactable data.
@@ -99,19 +99,20 @@ 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, value, setValue) {
102
+ function useSynced(def, handlers) {
103
103
  const [v, setV] = (0, react_1.useState)(def);
104
- if (value !== undefined) {
104
+ if (handlers !== undefined) {
105
+ const [value, setValue] = handlers;
105
106
  (0, react_1.useEffect)(() => {
107
+ if ((0, lodash_1.isEqual)(v, value))
108
+ return;
106
109
  setV(value);
107
- }, [value, setV]);
108
- }
109
- if (setValue !== undefined) {
110
+ }, [value, v, setV]);
110
111
  (0, react_1.useEffect)(() => {
111
112
  if ((0, lodash_1.isEqual)(v, value))
112
113
  return;
113
114
  setValue(v);
114
- }, [v, setValue]);
115
+ }, [v, value, setValue]);
115
116
  }
116
117
  return [v, setV];
117
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.76",
3
+ "version": "0.0.77",
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": {