Skip to content

Commit 6dc766f

Browse files
committed
Make isLoading true by default #13
1 parent 382ab45 commit 6dc766f

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
React hook for conveniently use Fetch API.
88

9-
* **Tiny** (396 B). Calculated by [size-limit](https://github.com/ai/size-limit)
9+
* **Tiny** (397 B). Calculated by [size-limit](https://github.com/ai/size-limit)
1010
* Both **Flow** and **TypeScript** types included
1111

1212
```javascript

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fetch-hook",
3-
"version": "1.6.4",
3+
"version": "1.7.0",
44
"description": "React fetch hook",
55
"scripts": {
66
"flow": "flow",
@@ -31,7 +31,7 @@
3131
"ignore": [
3232
"react"
3333
],
34-
"limit": "396 B",
34+
"limit": "397 B",
3535
"path": "index.js"
3636
},
3737
{

test/useFetch.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ describe("useFetch", () => {
2626
});
2727
});
2828

29+
it("isLoading by default", async () => {
30+
fetch.mockResponse(JSON.stringify({ data: "12345" }));
31+
32+
const Component = () => {
33+
const result = useFetch("https://google.com");
34+
return <div>{result.isLoading && "test"}</div>;
35+
};
36+
37+
const { container, rerender } = render(<Component />);
38+
expect(container).toHaveTextContent("test");
39+
});
40+
2941
it("call with url and options", async () => {
3042
fetch.mockResponse(JSON.stringify({ data: "12345" }));
3143
const options = {

usePromise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ function usePromise (
77
) {
88
var inputs = Array.prototype.slice.call(arguments, [1])
99
var state = React.useState({
10-
isLoading: false
10+
isLoading: !!callFunction
1111
})
1212

1313
React.useEffect(function () {
1414
if (!callFunction) {
1515
return
1616
}
17-
state[1]({ data: state[0].data, isLoading: true })
17+
!state[0].isLoading && state[1]({ data: state[0].data, isLoading: true })
1818
callFunction.apply(null, inputs)
1919
.then(function (data) {
2020
state[1]({

0 commit comments

Comments
 (0)