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
26 changes: 8 additions & 18 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
node-version: [10, 12]
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v1
Expand All @@ -25,21 +25,11 @@ jobs:
- name: Install latest npm
run: npm install --global npm@latest

- name: npm install and lint
run: |
npm install
npm run lint

# Windows environment currently has random case drive letter
# that Actions created.
# See more: https://github.com/stylelint/stylelint/issues/4337
- name: Test (Windows)
if: matrix.os == 'windows-latest'
run: |
cd ..
cd D:\a\use-api\use-api
npm test

- name: Test (Unix)
if: matrix.os != 'windows-latest'
- name: npm install
run: npm install

- name: Linting
run: npm run lint

- name: Testing
run: npm test
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project are documented in this file.

- Added: Further tests
- Added: `headers` argument.
- Changed: NPM dependency updates.

## 0.4.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { data, loading, error, refresh } = useApi({
pollInterval: 10000,
payload: { keywords: "hello" },
method: "post",
changed: data => console.log("The data changed!", data)
changed: (data) => console.log("The data changed!", data),
});
```

Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const useApi = ({
payload,
method = "get",
headers,
changed
changed,
}) => {
const [data, setData] = useState({});
const [error, setError] = useState(null);
Expand Down Expand Up @@ -73,9 +73,9 @@ const useApi = ({
(method === "get"
? { params: currentPayload }
: { data: currentPayload })),
...(currentHeaders && { headers: currentHeaders })
...(currentHeaders && { headers: currentHeaders }),
})
.then(response => {
.then((response) => {
// Make sure there are no errors reported
setError(null);

Expand All @@ -91,7 +91,7 @@ const useApi = ({
setData(response.data);
}
})
.catch(thrown => {
.catch((thrown) => {
// Only error on genuine errors, not cancellations
if (!axios.isCancel(thrown)) setError(thrown.message);
})
Expand All @@ -118,7 +118,7 @@ const useApi = ({
currentHeaders,
method,
lastData,
changedRef
changedRef,
]);

return { data, loading, changed, error, refresh: () => setPoll(poll + 1) };
Expand Down
Loading