@cripty2001/utils 0.0.136 → 0.0.138

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.
@@ -19,7 +19,7 @@ export type FormComponentProps<T extends Record<string, string>> = {
19
19
  callback: (values: T) => void | Promise<void>;
20
20
  };
21
21
  value: T;
22
- setValue: React.Dispatch<React.SetStateAction<T>>;
22
+ setValue: (v: T) => void;
23
23
  variant: TypeofRecord<InputComponentPropsVariants> & {
24
24
  button: string;
25
25
  };
@@ -15,10 +15,10 @@ function FormComponent(props) {
15
15
  }), [props.variant]);
16
16
  return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' }, children: [props.inputs.map((input, index) => (() => {
17
17
  const value = props.value[input.key];
18
- const setValue = (v) => props.setValue(prev => ({
19
- ...prev,
18
+ const setValue = (v) => props.setValue({
19
+ ...props.value,
20
20
  [input.key]: v
21
- }));
21
+ });
22
22
  const baseProps = {
23
23
  label: input.label,
24
24
  value: value,
@@ -56,7 +56,7 @@ export declare function useSynced<T extends any>(def: T, value: T | undefined, s
56
56
  * Wraps an async function into a reactable data.
57
57
  *
58
58
  * @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
59
- * @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem.
59
+ * @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem. If null, this function will act like an useEffect with an empty dependency array.
60
60
  * @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed
61
61
  * @returns The dispatcher
62
62
  *
@@ -139,7 +139,7 @@ function useSynced(def, value, setValue) {
139
139
  * Wraps an async function into a reactable data.
140
140
  *
141
141
  * @param f The async function to call. It should return a promise that resolves to the data. It is not reactive
142
- * @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem.
142
+ * @param data The data to give to f. It must be stable, as anything in the dependency array of the useEffect and similars in the react ecosystem. If null, this function will act like an useEffect with an empty dependency array.
143
143
  * @param debouce Debounce time in ms. Default to 200ms. The async function will not be called if this time has not passed since the useAsync first invocation or value change. If another change happens during the wait, the first function call is never executed
144
144
  * @returns The dispatcher
145
145
  *
@@ -148,10 +148,12 @@ function useSynced(def, value, setValue) {
148
148
  */
149
149
  function useAsync(f, data, debouce = 200) {
150
150
  // Initing reactive input
151
- const [input, setInput] = (0, react_1.useRef)(whispr_1.Whispr.create(data)).current;
152
- (0, react_1.useEffect)(() => {
153
- setInput(data); // Debouncing already handled by dispatcher
154
- }, [data, setInput]);
151
+ const [input, setInput] = (0, react_1.useRef)(whispr_1.Whispr.create(data ?? (0, _1.getRandomId)())).current;
152
+ if (data !== null) {
153
+ (0, react_1.useEffect)(() => {
154
+ setInput(data); // Debouncing already handled by dispatcher
155
+ }, [data, setInput]);
156
+ }
155
157
  // Initing dispatcher
156
158
  const dispatcher = (0, react_1.useRef)(new Dispatcher_1.Dispatcher(input, f, debouce)).current;
157
159
  // Returning dispatcher
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.136",
3
+ "version": "0.0.138",
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": {