Skip to content

Commit f569e99

Browse files
Amit DabadeAmit Dabade
authored andcommitted
1. README file update 2. code optimization
1 parent df12558 commit f569e99

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1-
## What is this?
1+
## What is useFetch?
22

3-
A simple react component that prints Hello, {username}!
3+
React hook to fetch data from network, with some additional awesome features.
44

55
## Installation:
66

77
```
8-
npm i @amitdabade/react-hello --save
8+
npm i @react-use-hooks/use-fetch --save
99
````
1010
1111
## Code:
1212
1313
```
1414
import React from 'react';
1515
import ReactDOM from 'react-dom';
16-
import { Hello } from "@amitdabade/react-hello";
16+
import { useFetch } from "@react-use-hooks/use-fetch";
1717

1818
function App() {
19+
const { fetch, data, error, fetching, status, request, response } = useFetch({
20+
url: "https://jsonplaceholder.typicode.com/todos/1"
21+
});
1922
return (
20-
<div>
21-
<Hello name="Amit" />
23+
<div className="App">
24+
<h1>React-use-hooks : useFetch</h1>
25+
<button onClick={() => fetch()}>Fetch Data</button>
26+
<p>Fetching: {fetching + ""}</p>
27+
<p>Status: {status}</p>
28+
<p>Request Method: {request?.method}</p>
29+
<p>Request URL: {request?.url}</p>
30+
<p>Response code: {response?.status}</p>
31+
<p>Response Text: {response?.statusText}</p>
32+
<p>Data: {data && JSON.stringify(data)}</p>
33+
<p>Error: {error && error.message}</p>
2234
</div>
23-
)
35+
);
2436
}
2537

2638
ReactDOM.render(<App />, document.getElementById('root'));
2739
```
2840
2941
## Demo:
3042
31-
[Demo](https://codesandbox.io/s/react-hello-vnuw5)
43+
[Demo](https://codesandbox.io/s/react-use-fetch-demo-5kcix)
3244
3345
## Options:
3446
35-
name : _string_ (Default: "World")
47+
url : _string_
3648
3749
## License:
3850

src/components/Hello/Hello.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/components/Hello/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import React from "react";
22
import { storiesOf } from "@storybook/react";
33
import "./styles.css";
44

5-
import { useFetch } from "./../use-fetch";
5+
import { useFetch } from "../use-fetch";
66

77
const stories = storiesOf("Basic", module);
88

99
stories.add("Basic", () => {
10-
const { fetch, data, error, fetching, status, response } = useFetch({
11-
url: "https://jsonplaceholder.typicode.com/users/1",
10+
const { fetch, data, error, fetching, status, request, response } = useFetch({
11+
url: "https://jsonplaceholder.typicode.com/todos/1",
1212
});
1313
return (
14-
<div>
15-
<h2>useFetch - Basics</h2>
14+
<div className="App">
15+
<h1>React-use-hooks : useFetch</h1>
1616
<button onClick={() => fetch()}>Fetch Data</button>
1717
<p>Fetching: {fetching + ""}</p>
1818
<p>Status: {status}</p>
19+
<p>Request Method: {request?.method}</p>
20+
<p>Request URL: {request?.url}</p>
1921
<p>Response code: {response?.status}</p>
2022
<p>Response Text: {response?.statusText}</p>
2123
<p>Data: {data && JSON.stringify(data)}</p>

src/stories/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.App {
2+
font-family: sans-serif;
3+
}
4+

0 commit comments

Comments
 (0)