Skip to content

Commit 9444fe9

Browse files
Merge pull request #6 from JCustin/patch-1
Updating README
2 parents 3dc5983 + 7da6a49 commit 9444fe9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
# useFetch
22

3-
A quick and easy hook for using Fetch with React.
3+
Utilizes Fetch within React to grab data from HTTP resources.
44

55
## Install
66

77
`npm install @chrislaughlin/usefetch`
88

9-
## Usage
9+
## Parameters
10+
11+
| Term | Definition |
12+
|----------------|------------------------------------------------------------|
13+
| URL | The HTTP resource required to fetch data. |
14+
| `fetchOptions` | Additional parameters or limits to specify the fetch call. |
15+
16+
`useFetch` is functional with standard `Fetch` options, as well as customizable options. Currently, there is only one additional option available:
17+
18+
| Term | Definition |
19+
|-----------|---------------------------------------------------------------------------------|
20+
| `timeout` | A customizable number of milliseconds measured before aborting the fetch call. |
21+
22+
## Requesting a fetch call with useFetch
23+
24+
`useFetch` is a simple function to grab data from a HTTP resource within the React web framework. To utilize `useFetch`, a URL is required. While `fetchOptions` isn't required, it is recommended to specify and customize the fetch call. Multipe `fetchOptions` can be used in one fetch call.
1025

1126
```jsx
1227
import useFetch from '@chrislaughlin/usefetch'
@@ -38,6 +53,8 @@ const Example = () => {
3853

3954
### Aborting a request via custom timeout
4055

56+
The `timeout` option can be used to abort a fetch call. `timeout` is measured in a customizable number of milliseconds that will trigger when fully counted.
57+
4158
```jsx
4259
import useFetch from '@chrislaughlin/usefetch'
4360

@@ -64,6 +81,8 @@ const CustomTimeout = () => {
6481

6582
### Aborting a request via consuming application
6683

84+
With React, a fetch call can be aborted by consuming another application. This is performed by using the effect hook built natively in React.
85+
6786
```jsx
6887
import useFetch from '@chrislaughlin/usefetch'
6988

@@ -98,3 +117,13 @@ const AbortExample = () => {
98117
)
99118
};
100119
```
120+
## Items returned from fetch calls
121+
122+
There are several items which may be returned when requesting a fetch call.
123+
124+
| Term | Definition |
125+
|--------------|-----------------------------------------------------------------------------------------|
126+
| Data | The content being fetched from a HTTP resource. |
127+
| Error | States an issue with the fetch call, made when the data cannot properly load. |
128+
| isLoading | Checks if the request is being loaded, as well as clearing out prior timeout functions. |
129+
| abortConsole | Cancels the fetch call. |

0 commit comments

Comments
 (0)