Skip to content

Commit ca7b278

Browse files
committed
01-Writing your first React GraphQL Client
1 parent 7d66b65 commit ca7b278

File tree

4 files changed

+62
-24
lines changed

4 files changed

+62
-24
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"axios": "^0.18.0",
67
"react": "^16.6.0",
78
"react-dom": "^16.6.0",
89
"react-scripts": "2.0.5"

src/App.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
import React, { Component } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
2+
import axios from 'axios';
3+
4+
const TITLE = 'React GraphQL GitHub Client';
5+
6+
const axiosGitHubGraphQL = axios.create({
7+
baseURL: 'https://api.github.com/graphql',
8+
headers: {
9+
Authorization: `bearer ${
10+
process.env.REACT_APP_GITHUB_PERSONAL_ACCESS_TOKEN
11+
}`,
12+
},
13+
});
414

515
class App extends Component {
16+
state = {
17+
path: 'the-road-to-learn-react/the-road-to-learn-react',
18+
};
19+
20+
componentDidMount() {
21+
// fetch data
22+
}
23+
24+
onChange = event => {
25+
this.setState({ path: event.target.value });
26+
};
27+
28+
onSubmit = event => {
29+
// fetch data
30+
31+
event.preventDefault();
32+
};
33+
634
render() {
35+
const { path } = this.state;
36+
737
return (
8-
<div className="App">
9-
<header className="App-header">
10-
<img src={logo} className="App-logo" alt="logo" />
11-
<p>
12-
Edit <code>src/App.js</code> and save to reload.
13-
</p>
14-
<a
15-
className="App-link"
16-
href="https://reactjs.org"
17-
target="_blank"
18-
rel="noopener noreferrer"
19-
>
20-
Learn React
21-
</a>
22-
</header>
38+
<div>
39+
<h1>{TITLE}</h1>
40+
41+
<form onSubmit={this.onSubmit}>
42+
<label htmlFor="url">
43+
Show open issues for https://github.com/
44+
</label>
45+
<input
46+
id="url"
47+
type="text"
48+
value={path}
49+
onChange={this.onChange}
50+
style={{ width: '300px' }}
51+
/>
52+
<button type="submit">Search</button>
53+
</form>
54+
55+
<hr />
56+
57+
{/* Here comes the result! */}
2358
</div>
2459
);
2560
}

src/logo.svg

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

0 commit comments

Comments
 (0)