Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/qiushiyan/use-action-status
- Owner: qiushiyan
- Created: 2024-06-09T03:20:59.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-09T03:26:31.000Z (7 months ago)
- Last Synced: 2024-11-01T15:05:26.549Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)}}
);
```