@cripty2001/utils 0.0.77 → 0.0.79

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,10 +99,12 @@ 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)(() => {
107
109
  if ((0, lodash_1.isEqual)(v, value))
108
110
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.77",
3
+ "version": "0.0.79",
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": {