@cripty2001/utils 0.0.247 → 0.0.249

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.
@@ -3,5 +3,6 @@ export type ButtonProps = {
3
3
  children: React.ReactElement;
4
4
  className?: string;
5
5
  onError?: (error: unknown) => void;
6
+ loader?: React.ReactElement;
6
7
  };
7
- export default function Button({ onClick, children, className, onError }: ButtonProps): import("react").JSX.Element;
8
+ export default function Button({ onClick, children, className, onError, loader }: ButtonProps): import("react").JSX.Element;
@@ -4,7 +4,12 @@ exports.default = Button;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const lucide_react_1 = require("lucide-react");
6
6
  const react_1 = require("react");
7
- function Button({ onClick, children, className, onError }) {
7
+ function Button({ onClick, children, className, onError, loader }) {
8
+ const Loader = loader ?? (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { style: {
9
+ width: '1rem',
10
+ height: '1rem',
11
+ animation: 'spin 1s linear infinite',
12
+ } });
8
13
  const [loading, setLoading] = (0, react_1.useState)(false);
9
14
  const [error, setError] = (0, react_1.useState)(null);
10
15
  const handleClick = async () => {
@@ -33,11 +38,7 @@ function Button({ onClick, children, className, onError }) {
33
38
  textAlign: 'center',
34
39
  cursor: 'pointer',
35
40
  }, children: loading ?
36
- (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { style: {
37
- width: '1rem',
38
- height: '1rem',
39
- animation: 'spin 1s linear infinite',
40
- } }) :
41
+ Loader :
41
42
  children }), error && (0, jsx_runtime_1.jsx)("div", { style: {
42
43
  color: '#ef4444'
43
44
  }, children: error })] }) }));
@@ -91,13 +91,13 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
91
91
  /**
92
92
  * Like useAsync, but it also automatically re-execute the async function periodically
93
93
  *
94
- * @param f @see useAsync
95
94
  * @param data @see useAsync
96
95
  * @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
96
+ * @param f @see useAsync
97
97
  *
98
98
  * @returns @see useAsync
99
99
  */
100
- export declare function useAsyncPeriodic<I, O>(f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>, data: I, interval: number): Dispatcher<any, O>;
100
+ export declare function useAsyncPeriodic<I, O>(data: I, interval: number, f: (input: I, setProgress: (p: number) => void, signal: AbortSignal) => Promise<O>): Dispatcher<any, O>;
101
101
  /**
102
102
  * Async version of useEffect with debouncing. Executes an async function as a side effect when data changes.
103
103
  *
@@ -200,18 +200,18 @@ function useAsync(f, data, debouce = 200) {
200
200
  /**
201
201
  * Like useAsync, but it also automatically re-execute the async function periodically
202
202
  *
203
- * @param f @see useAsync
204
203
  * @param data @see useAsync
205
204
  * @param interval The interval to re-execute the async function. If null, the async function will not be re-executed.
205
+ * @param f @see useAsync
206
206
  *
207
207
  * @returns @see useAsync
208
208
  */
209
- function useAsyncPeriodic(f, data, interval) {
209
+ function useAsyncPeriodic(data, interval, f) {
210
210
  const timer = useClock(interval);
211
211
  const bundle = (0, react_1.useMemo)(() => {
212
212
  return {
213
213
  data,
214
- interval
214
+ timer
215
215
  };
216
216
  }, [data, timer]);
217
217
  return useAsync((i, p, s) => f(i.data, p, s), bundle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.247",
3
+ "version": "0.0.249",
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": {