Skip to content

Commit 495ff6c

Browse files
committed
initial commit
0 parents  commit 495ff6c

13 files changed

Lines changed: 9723 additions & 0 deletions

File tree

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*]
2+
charset = utf-8
3+
end_of_line = lf
4+
indent_size = 2
5+
indent_style = space
6+
insert_final_newline = true
7+
root = true
8+
trim_trailing_whitespace = true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*.log
3+
dist
4+
.cache

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018-present Dominik Biedebach
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# `@d2k/react-github`
2+
3+
> React hooks for Github API integrations
4+
5+
> You'll need to install `react`, `react-dom`, etc at `^16.8.4`
6+
7+
## Install
8+
9+
```sh
10+
npm i @d2k/react-github --save
11+
```
12+
13+
## Usage
14+
15+
### Get repos by username
16+
17+
```js
18+
import { useRepos } from "@d2k/react-github";
19+
20+
function MyComponent() {
21+
const { repos, loading, error } = useRepos("nat");
22+
23+
return (
24+
<div>
25+
{loading && <div>Loading repositories</div>}
26+
{error && <div>{err}</div>}
27+
{repos &&
28+
repos.length > 0 &&
29+
repos.map(repo => <div key={repo.id}>{repo.name}</div>)}
30+
</div>
31+
);
32+
}
33+
```
34+
35+
### Get user
36+
37+
```js
38+
import { useUser } from "@d2k/react-github";
39+
40+
function MyComponent() {
41+
const { user, loading, error } = useUser("nat");
42+
43+
return (
44+
<div>
45+
{loading && <div>Loading repositories</div>}
46+
{error && <div>{err}</div>}
47+
{user && (
48+
<div>
49+
<h1>{user.login}</h1>
50+
<img src={user.avatar_url} />
51+
</div>
52+
)}
53+
</div>
54+
);
55+
}
56+
```

docs/components/Repos.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import { useRepos } from "../../src";
3+
4+
const Repos = () => {
5+
const { repos, loading, error } = useRepos("bdbch");
6+
7+
return (
8+
<div>
9+
<h1>Repos by username</h1>
10+
{loading && <div>Loading repositories from Github</div>}
11+
{error && <div>{error}</div>}
12+
{repos &&
13+
repos.length > 0 &&
14+
repos.map(repo => (
15+
<div key={repo.id}>
16+
<h4>{repo.name}</h4>
17+
{repo.description && <p>{repo.description}</p>}
18+
</div>
19+
))}
20+
</div>
21+
);
22+
};
23+
24+
export default Repos;

docs/components/User.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import { useUser } from "../../src";
3+
4+
const Repos = () => {
5+
const { user, loading, error } = useUser("bdbch");
6+
7+
return (
8+
<div>
9+
<h1>User</h1>
10+
{loading && <div>Loading user from Github</div>}
11+
{error && <div>{error}</div>}
12+
{user && (
13+
<div>
14+
<h4>{user.login}</h4>
15+
<img src={user.avatar_url} />
16+
</div>
17+
)}
18+
</div>
19+
);
20+
};
21+
22+
export default Repos;

docs/example.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Example</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script src="./example.js"></script>
12+
</body>
13+
</html>

docs/example.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import { render } from "react-dom";
3+
import Repos from "./components/Repos";
4+
import User from "./components/User";
5+
6+
function App() {
7+
return (
8+
<div>
9+
<Repos />
10+
<hr />
11+
<User />
12+
<hr />
13+
</div>
14+
);
15+
}
16+
17+
render(<App />, window.root);

0 commit comments

Comments
 (0)