Skip to content

Commit 8c1ab01

Browse files
author
John Richard Chipps-Harding
authored
Arguments now a single object (#16)
1 parent 34e8583 commit 8c1ab01

File tree

6 files changed

+90
-73
lines changed

6 files changed

+90
-73
lines changed

Diff for: .npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.git
22
.github
3+
coverage

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project are documented in this file.
44

5+
## Unreleased
6+
7+
- Changed: Input arguments now a configuration object.
8+
59
## 0.2.2
610

711
- Fixed: `payload` equality fix.

Diff for: README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ If you need a simple way to load data quickly this is for you. It allows you to
1313
You can optionally specify a polling interval and manually trigger a refresh. It also gracefully cancels any open requests if you decide to change the URL and restarts timers if the polling interval changes.
1414

1515
```javascript
16-
const { data, loading, changed, error, refresh } = useApi(
17-
"https://some-api.com",
18-
10000
19-
);
16+
const { data, loading, changed, error, refresh } = useApi({
17+
apiEndpoint: "https://some-api.com",
18+
pollInterval: 10000
19+
});
2020
```
2121

2222
## Installation
@@ -37,7 +37,10 @@ import useApi from '@signal-noise/use-api';
3737
import PeopleList from './PeopleList';
3838

3939
const PeopleList = () = {
40-
const { data, loading, error, refresh } = useApi("https://some-api.com", 10000);
40+
const { data, loading, error, refresh } = useApi({
41+
apiEndpoint: "https://some-api.com",
42+
pollInterval: 10000
43+
)};
4144

4245
const people = data.people || [];
4346

@@ -62,7 +65,11 @@ import PeopleList from './PeopleList';
6265
const PeopleSearch = () = {
6366
const [keywords, setKeywords] = useState("kazumi");
6467

65-
const { data } = useApi("https://some-api.com", 0, { keywords }, "post");
68+
const { data } = useApi({
69+
apiEndpoint: "https://some-api.com",
70+
payload: { keywords },
71+
method: "post"
72+
});
6673

6774
const people = data.people || [];
6875

Diff for: index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const isEqual = require("lodash.isequal");
44

55
const { CancelToken } = axios;
66

7-
const useApi = (
7+
const useApi = ({
88
apiEndpoint,
9-
pollInterval,
9+
pollInterval = 0,
1010
payload,
1111
method = "get",
1212
changed
13-
) => {
13+
}) => {
1414
const [data, setData] = useState({});
1515
const [error, setError] = useState(null);
1616
const [loading, setLoading] = useState(true);

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"scripts": {
2525
"test": "jest",
26+
"test:watch": "jest --watch",
2627
"coverage": "jest --coverage",
2728
"release": "np",
2829
"lint": "npm-run-all --parallel lint:*",

0 commit comments

Comments
 (0)