Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/auroratide/use-async
Simple React hook for handling asynchronous operations
https://github.com/auroratide/use-async
Last synced: about 14 hours ago
JSON representation
Simple React hook for handling asynchronous operations
- Host: GitHub
- URL: https://github.com/auroratide/use-async
- Owner: Auroratide
- License: isc
- Created: 2019-06-13T13:11:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T00:38:26.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T06:36:12.255Z (7 days ago)
- Language: JavaScript
- Size: 708 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# use-async
**use-async** is just another React hook for handling asynchronous operations in a stateful way! It automatically juggles three potential states an operation can be in (_waiting, done, and error_), providing these as variables which your component can conditionally render upon.
```jsx
import useAsync from '@auroratide/use-async';
import api from './api';const PostListPage = () => {
const { result, waiting, error, call } = useAsync(api.get);return <>
Get Data
{waiting && }
{error && }
{result && }
>;
}
```## How to use
To see how to use this library, check out the `examples` folder for sample usages! The goal is to _actually_ use tests as documentation by reframing the paradigm into thinking of our tests as "example usages". This means you can learn how to use the library directly from the code, and this means less written documentation that's prone to becoming out-of-date.