Skip to content

Commit ec3a36b

Browse files
committed
Add basic example
1 parent be6c1f4 commit ec3a36b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

examples/basic/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<div id="root"></div>
9+
<script src="./index.js"></script>
10+
</body>
11+
</html>

examples/basic/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import useFetch from "../../index";
4+
5+
6+
const App = () => {
7+
const {isLoading, data} = useFetch(`https://swapi.co/api/people/1`);
8+
9+
console.log(isLoading, data);
10+
11+
return <div>
12+
<p>isLoading: {isLoading && "true" || "false"}</p>
13+
<p>Name: {data && data.name}</p>
14+
</div>
15+
};
16+
17+
18+
if (root) {
19+
ReactDOM.render(
20+
<App />,
21+
document.getElementById("root")
22+
);
23+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"test": "jest --silent",
1010
"size": "size-limit",
1111
"lint": "eslint '**/*.{js,jsx}' --quiet",
12+
"run:example:basic": "parcel ./examples/basic/index.html",
1213
"run:example:depends": "parcel ./examples/depends/index.html",
1314
"run:example:pagination": "parcel ./examples/pagination/index.html --no-cache",
1415
"prepublish": "npm run flow:check && npm run typescript && npm run lint && npm run size && npm run test"

0 commit comments

Comments
 (0)