diff --git a/package.json b/package.json index b59fe19..04ca60d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.3.3", + "version": "1.4.0", "name": "@kernelui/core", "description": "Kernel UI Core.", "scripts": { diff --git a/src/Async.tsx b/src/Async.tsx index 8ae1dc7..cea245c 100644 --- a/src/Async.tsx +++ b/src/Async.tsx @@ -35,10 +35,10 @@ export type PromiseFn = () => Promise; /** * React hook for promise result retrieval. - * @param promise The promise or a function that produces a promise. + * @param promise The promise or a function which produces a promise. * @param deps When one of the `deps` change, it will wait for the promise again. */ -export function useAsync(promise: Promisable|PromiseFn, deps: any[] = []): AsyncState +export function useAsync(promise: Promisable|PromiseFn, deps: any[] = []): [AsyncState, React.Dispatch] { // Get the actual promise from the function if there is one. if ((promise as PromiseFn)?.call) @@ -94,7 +94,10 @@ export function useAsync(promise: Promisable|PromiseFn, deps: any[] = [ }); }, deps); - return state; // Return the current async state. + // Return the current async state and a dispatch data function. + return [state, (data: T) => { + updateState({data: data}); + }]; } /** @@ -133,7 +136,7 @@ export function Async({promise, fallback, children}: { }) { // Get async data from given promise. - const async = useAsync(promise, [promise]); + const [async] = useAsync(promise, [promise]); return ( // Wait for promised data. diff --git a/src/Components/Pagination/Paginate.tsx b/src/Components/Pagination/Paginate.tsx index 6686cb1..6b4b91c 100644 --- a/src/Components/Pagination/Paginate.tsx +++ b/src/Components/Pagination/Paginate.tsx @@ -83,7 +83,7 @@ export function AsyncPaginate({ count, getData, children }: { }) { // Getting pages count. - const asyncCount = useAsync(count, []); + const [asyncCount] = useAsync(count, []); return ( }> @@ -127,7 +127,7 @@ export function AsyncPage({page, getData, render}: { }, [page]); // Getting page data. - const asyncPageData = useAsync(getPageData, [getPageData]); + const [asyncPageData] = useAsync(getPageData, [getPageData]); return ( }>