Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/qiushiyan/use-action-status

A React hook for monitoring the status of any async function
https://github.com/qiushiyan/use-action-status

Last synced: about 1 month ago
JSON representation

A React hook for monitoring the status of any async function

Awesome Lists containing this project

README

        

# use-action-status

A React hook for monitoring the status of any async operation.

## Examples

```tsx
const [response, setResponse] = useState(null);

const { action, isPending, isDelayed, isError, error } = useActionStatus(
async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/posts/1");
setResponse(await res.json());

// or any other async code
},
{ delayTimeout: 3000 }
);

return (


Fetch
{isPending &&

Loading...

}

{isError &&

Error: {error.message}

}
{isDelayed &&

This request took longer than usual

}
{response &&
{JSON.stringify(response, null, 2)}
}

);
```