@weser/actions 0.0.16 → 0.0.17
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.
- package/dist/useAction.d.ts +4 -4
- package/dist/useAction.js +2 -2
- package/package.json +2 -2
package/dist/useAction.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ type State<T> = {
|
|
|
4
4
|
data: T | null;
|
|
5
5
|
error: string | null;
|
|
6
6
|
};
|
|
7
|
-
type T_ActionConfig<T> = {
|
|
8
|
-
onSuccess?: (data: T) => void;
|
|
9
|
-
onError?: (error: string) => void;
|
|
7
|
+
type T_ActionConfig<T, P> = {
|
|
8
|
+
onSuccess?: (data: T, payload: P) => void;
|
|
9
|
+
onError?: (error: string, payload: P) => void;
|
|
10
10
|
};
|
|
11
|
-
export default function useAction<T, P extends Array<any>>(action: (...payload: P) => Promise<T_ActionResponse<T>>, config?: T_ActionConfig<T>): [State<T>, (...payload: P) => void];
|
|
11
|
+
export default function useAction<T, P extends Array<any>>(action: (...payload: P) => Promise<T_ActionResponse<T>>, config?: T_ActionConfig<T, P>): [State<T>, (...payload: P) => void];
|
|
12
12
|
export {};
|
package/dist/useAction.js
CHANGED
|
@@ -15,7 +15,7 @@ export default function useAction(action, config = {}) {
|
|
|
15
15
|
const [error, data] = await action(...payload);
|
|
16
16
|
if (error !== null || !data) {
|
|
17
17
|
if (onError) {
|
|
18
|
-
onError(error);
|
|
18
|
+
onError(error, payload);
|
|
19
19
|
}
|
|
20
20
|
setState({
|
|
21
21
|
...state,
|
|
@@ -26,7 +26,7 @@ export default function useAction(action, config = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
if (onSuccess) {
|
|
29
|
-
onSuccess(data);
|
|
29
|
+
onSuccess(data, payload);
|
|
30
30
|
}
|
|
31
31
|
setState({
|
|
32
32
|
...state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "React helpers for working with server actions",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"rimraf": "^3.0.2",
|
|
53
53
|
"typescript": "^5.4.5"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "71b258e9fc17ff82728fc3b51ac935f48b11f204"
|
|
56
56
|
}
|