Skip to content

Commit 7ebb402

Browse files
committed
improve readme
1 parent 0b55d48 commit 7ebb402

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ This library does not yet support React Suspense, but hopefully it will as soon
6565
#### How can I debounce the request
6666

6767
It is possible to debounce a promise.
68-
I recommend my package [awesome-debounce-promise](https://github.com/slorber/awesome-debounce-promise) instead, because it handles concucrrency issues and have React in mind (particularly building a debounced search input/autocomplete)
68+
69+
I recommend [awesome-debounce-promise](https://github.com/slorber/awesome-debounce-promise), as it handles nicely potential concurrency issues and have React in mind (particularly the common usecase of a debounced search input/autocomplete)
70+
6971
As debounced functions are stateful, we have to "store" the debounced function inside a component. We'll use for that [use-constant](https://github.com/Andarist/use-constant) (backed by `useRef`).
7072

7173
```tsx
@@ -75,15 +77,17 @@ const StarwarsHero = ({ id }) => {
7577
AwesomeDebouncePromise(fetchStarwarsHero, 1000)
7678
);
7779

78-
// Simply use it
80+
// Simply use it with useAsync
7981
const asyncHero = useAsync(debouncedFetchStarwarsHero, [id]);
82+
8083
return <div>...</div>;
8184
};
8285
```
8386

8487
#### How to use request cancellation
8588

8689
You can use the `useAsyncAbortable` alternative. The async function provided will receive `(abortSignal, ...params)` .
90+
8791
The library will take care of triggering the abort signal whenever a new async call is made so that only the last request is not cancelled.
8892
It is your responsability to wire the abort signal appropriately.
8993

@@ -122,7 +126,9 @@ const StarwarsHero = ({ id }) => {
122126
};
123127
```
124128

125-
#### How to refresh the data
129+
#### How to refresh / refetch the data
130+
131+
If your params are not changing, yet you need to refresh the data, you can call `execute()`
126132

127133
```tsx
128134
const StarwarsHero = ({ id }) => {

0 commit comments

Comments
 (0)