Skip to content

Commit

Permalink
fix type usePromise
Browse files Browse the repository at this point in the history
  • Loading branch information
UpperCod committed Apr 10, 2022
1 parent 409de20 commit fb9a377
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@atomico/hooks",
"description": "Series of utilities in hooks format to extend the operation of Atomico",
"version": "3.33.4",
"version": "3.33.5",
"type": "module",
"workspaces": [
"src/**/*"
Expand Down
10 changes: 7 additions & 3 deletions src/use-promise/use-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export const Status = {
*/
const initalState = () => [, ""];
/**
* @template {()=>Promise<any>} T
* @example
* ```js
* const [executePromise, setExecutePromise] = useState();
* const [ result, status ] = usePromise(()=>fetch("./any").then(res=>res.json()),executePromise);
* ```
* @param {()=>Promise<any>} promise -
* @param {T} promise -
* @param {boolean} run
* @param {any[]} [args]
* @returns {State}
* @returns {T extends (...args:any[])=>Promise<infer R> ? State<R> : State<any> }
*/
export function usePromise(promise, run, args = []) {
const [state, setState] = useState(initalState);
Expand Down Expand Up @@ -50,7 +51,10 @@ export function usePromise(promise, run, args = []) {

/**@typedef {Status["quiet"]|Status["pending"]|Status["fulfilled"]|Status["rejected"]} PromiseStatus */

/**@typedef {[any,PromiseStatus]} State */
/**
* @template T
* @typedef {[T,PromiseStatus]} State
**/

/**
* @typedef {Object} Status
Expand Down

0 comments on commit fb9a377

Please sign in to comment.