Skip to content

Commit 72c8b3b

Browse files
committed
replace swapi.co by swapi.dev
1 parent 0103880 commit 72c8b3b

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

README.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![NPM](https://img.shields.io/npm/dm/react-async-hook.svg)](https://www.npmjs.com/package/react-async-hook)
44
[![Build Status](https://travis-ci.com/slorber/react-async-hook.svg?branch=master)](https://travis-ci.com/slorber/react-async-hook)
55

6-
This library only **does one small thing**, and **does it well**.
6+
This library only **does one small thing**, and **does it well**.
77

88
Don't expect it to grow in size, because it is **feature complete**:
99

@@ -30,22 +30,18 @@ Don't expect it to grow in size, because it is **feature complete**:
3030

3131
**react-async-hook**:
3232

33-
34-
- ![](https://img.shields.io/bundlephobia/min/react-async-hook.svg)
35-
- ![](https://img.shields.io/bundlephobia/minzip/react-async-hook.svg)
36-
33+
- ![](https://img.shields.io/bundlephobia/min/react-async-hook.svg)
34+
- ![](https://img.shields.io/bundlephobia/minzip/react-async-hook.svg)
3735

3836
**React-Query**:
3937

40-
- ![](https://img.shields.io/bundlephobia/min/react-query.svg)
41-
- ![](https://img.shields.io/bundlephobia/minzip/react-query.svg)
42-
38+
- ![](https://img.shields.io/bundlephobia/min/react-query.svg)
39+
- ![](https://img.shields.io/bundlephobia/minzip/react-query.svg)
4340

4441
**SWR**:
4542

46-
- ![](https://img.shields.io/bundlephobia/min/swr.svg)
47-
- ![](https://img.shields.io/bundlephobia/minzip/swr.svg)
48-
43+
- ![](https://img.shields.io/bundlephobia/min/swr.svg)
44+
- ![](https://img.shields.io/bundlephobia/minzip/swr.svg)
4945

5046
## Things we don't support (by design):
5147

@@ -63,7 +59,6 @@ You can indeed build on top of this little lib to provide more advanced features
6359

6460
If you prefer a full-featured fetching library, try [SWR](https://github.com/vercel/swr) or [React-Query](https://github.com/tannerlinsley/react-query).
6561

66-
6762
## Usecase: loading async data into a component
6863

6964
The ability to inject remote/async data into a React component is a very common React need. Later we might support Suspense as well.
@@ -72,7 +67,7 @@ The ability to inject remote/async data into a React component is a very common
7267
import { useAsync } from 'react-async-hook';
7368

7469
const fetchStarwarsHero = async id =>
75-
(await fetch(`https://swapi.co/api/people/${id}/`)).json();
70+
(await fetch(`https://swapi.dev/api/people/${id}/`)).json();
7671

7772
const StarwarsHero = ({ id }) => {
7873
const asyncHero = useAsync(fetchStarwarsHero, [id]);
@@ -147,11 +142,10 @@ module.exports = {
147142
additionalHooks: '(useAsync|useAsyncCallback)',
148143
},
149144
],
150-
}
151-
}
145+
},
146+
};
152147
```
153148

154-
155149
# FAQ
156150

157151
#### How can I debounce the request
@@ -187,7 +181,7 @@ const searchStarwarsHero = async (
187181
abortSignal?: AbortSignal
188182
): Promise<StarwarsHero[]> => {
189183
const result = await fetch(
190-
`https://swapi.co/api/people/?search=${encodeURIComponent(text)}`,
184+
`https://swapi.dev/api/people/?search=${encodeURIComponent(text)}`,
191185
{
192186
signal: abortSignal,
193187
}
@@ -270,7 +264,7 @@ It is your responsability to wire the abort signal appropriately.
270264
const StarwarsHero = ({ id }) => {
271265
const asyncHero = useAsyncAbortable(
272266
async (abortSignal, id) => {
273-
const result = await fetch(`https://swapi.co/api/people/${id}/`, {
267+
const result = await fetch(`https://swapi.dev/api/people/${id}/`, {
274268
signal: abortSignal,
275269
});
276270
if (result.status !== 200) {
@@ -322,13 +316,18 @@ In this case you'd better use a closure with no arg define in the dependency arr
322316
Here, both `state.a` and `state.b` will trigger a refetch, despite b is not passed to the async fetch function.
323317

324318
```tsx
325-
const asyncSomething = useAsync(() => fetchSomething(state.a), [state.a,state.b]);
319+
const asyncSomething = useAsync(() => fetchSomething(state.a), [
320+
state.a,
321+
state.b,
322+
]);
326323
```
327324

328325
Here, only `state.a` will trigger a refetch, despite b being passed to the async fetch function.
329326

330327
```tsx
331-
const asyncSomething = useAsync(() => fetchSomething(state.a, state.b), [state.a]);
328+
const asyncSomething = useAsync(() => fetchSomething(state.a, state.b), [
329+
state.a,
330+
]);
332331
```
333332

334333
Note you can also use this to "build" a more complex payload. Using `useMemo` does not guarantee the memoized value will not be cleared, so it's better to do:
@@ -354,7 +353,6 @@ const asyncSomething = useAsyncCallback(async () => {
354353
asyncSomething.execute();
355354
```
356355

357-
358356
#### How to support retry?
359357

360358
Use a lib that simply adds retry feature to async/promises directly. Doesn't exist? Build it.

0 commit comments

Comments
 (0)