Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git
.github
coverage
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Unreleased

- Changed: Input arguments now a configuration object.

## 0.2.2

- Fixed: `payload` equality fix.
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ If you need a simple way to load data quickly this is for you. It allows you to
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.

```javascript
const { data, loading, changed, error, refresh } = useApi(
"https://some-api.com",
10000
);
const { data, loading, changed, error, refresh } = useApi({
apiEndpoint: "https://some-api.com",
pollInterval: 10000
});
```

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

const PeopleList = () = {
const { data, loading, error, refresh } = useApi("https://some-api.com", 10000);
const { data, loading, error, refresh } = useApi({
apiEndpoint: "https://some-api.com",
pollInterval: 10000
)};

const people = data.people || [];

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

const { data } = useApi("https://some-api.com", 0, { keywords }, "post");
const { data } = useApi({
apiEndpoint: "https://some-api.com",
payload: { keywords },
method: "post"
});

const people = data.people || [];

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const isEqual = require("lodash.isequal");

const { CancelToken } = axios;

const useApi = (
const useApi = ({
apiEndpoint,
pollInterval,
pollInterval = 0,
payload,
method = "get",
changed
) => {
}) => {
const [data, setData] = useState({});
const [error, setError] = useState(null);
const [loading, setLoading] = useState(true);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"coverage": "jest --coverage",
"release": "np",
"lint": "npm-run-all --parallel lint:*",
Expand Down
Loading