feature: Return result from server action
This commit is contained in:
parent
2c9b9c5b8f
commit
d1d9d8c9df
@ -10,7 +10,7 @@ import { useState, useEffect, useTransition, useRef } from "react";
|
||||
export const useServerAction = <P extends any[], R>(
|
||||
action: (...args: P) => Promise<R>,
|
||||
onFinished?: (_: R | undefined) => void,
|
||||
): [(...args: P) => Promise<R | undefined>, boolean] => {
|
||||
): [(...args: P) => Promise<R | undefined>, boolean, R | undefined] => {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [result, setResult] = useState<R>();
|
||||
const [finished, setFinished] = useState(false);
|
||||
@ -36,5 +36,5 @@ export const useServerAction = <P extends any[], R>(
|
||||
});
|
||||
};
|
||||
|
||||
return [runAction, isPending];
|
||||
return [runAction, isPending, result];
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user