@cripty2001/utils 0.0.161 → 0.0.163

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.
@@ -195,6 +195,6 @@ export type AsyncInputValue<C extends Record<string, JSONEncodable>, R extends R
195
195
  */
196
196
  export declare function useAsyncInput<C extends Record<string, JSONEncodable>, R extends Record<string, JSONEncodable>>(value: AsyncInputValue<C, R>, setValue: (value: AsyncInputValue<C, R>) => void, handler: (config: C) => Promise<R>): [
197
197
  value: C,
198
- setValue: (value: C) => void,
198
+ setValue: (updater: (draft: C) => C | void) => void,
199
199
  result: R | null
200
200
  ];
@@ -388,11 +388,16 @@ function useAsyncInput(value, setValue, handler) {
388
388
  (0, react_1.useEffect)(() => {
389
389
  if (result === null)
390
390
  return;
391
+ if (result._meta.ts <= meta.ts)
392
+ return;
391
393
  setValue(result);
392
394
  }, [result, setValue]);
393
- const returnedSetValue = (0, react_1.useCallback)((v) => {
395
+ const returnedSetValue = (0, react_1.useCallback)((updater) => {
396
+ const cloned = structuredClone(meta.config);
397
+ const new_data = updater(cloned);
398
+ const chosen = new_data ?? cloned;
394
399
  setMeta({
395
- config: v,
400
+ config: chosen,
396
401
  ts: Date.now(),
397
402
  });
398
403
  }, [setMeta]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.161",
3
+ "version": "0.0.163",
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": {