Skip to content

Commit 12d47b3

Browse files
committed
next: api
1 parent c65c074 commit 12d47b3

File tree

9 files changed

+322
-39
lines changed

9 files changed

+322
-39
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@
1919
npm-debug.log*
2020
yarn-debug.log*
2121
yarn-error.log*
22+
23+
.vscode

.vscode/settings.json

-3
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"firebase": "^5.5.5",
67
"react": "^16.5.2",
78
"react-dom": "^16.5.2",
89
"react-router-dom": "^4.3.1",

src/App.js

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
// import logo from './logo.svg';
3-
import './App.css';
3+
// import './App.css';
4+
import Router from './router';
45

5-
class App extends Component {
6-
constructor() {
7-
super()
8-
this.state = {
9-
count: 0,
10-
}
11-
}
12-
13-
addOne = () => {
14-
console.log("added one", this)
15-
this.setState(state => ({
16-
count: state.count + 1
17-
}))
18-
}
19-
what = () => {
20-
console.log(this)
21-
return this
22-
}
6+
class App extends React.Component {
237
render() {
248
return (
25-
<div className="App">
26-
<button onClick={this.addOne}> click me </button>
27-
<p>you clicked me {this.state.count} times.</p>
28-
<div className="this" onClick={this.what}><button>what is this fuck</button></div>
29-
</div>
9+
<Router/>
3010
);
3111
}
3212
}

src/api/api.js

Whitespace-only changes.

src/api/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import firebase from 'firebase/app'
2+
import 'firebase/database'
3+
4+
function createAPI ({config, version}) {
5+
firebase.initializeApp(config)
6+
return firebase.database().ref(version)
7+
}
8+
9+
const api = createAPI({
10+
version: '/v0',
11+
config: {
12+
databaseURL: 'https://hacker-news.firebaseio.com'
13+
}
14+
})

src/components/Home.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, {
2+
Component
3+
} from 'react'
4+
5+
class Home extends Component {
6+
constructor() {
7+
super()
8+
this.state = {
9+
10+
}
11+
}
12+
render() {
13+
return (
14+
<div className = "Home" >
15+
<p> this is Home 哦, 是主页哦! </p>
16+
</div>
17+
)
18+
}
19+
}
20+
21+
export default Home

src/router/index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import { HashRouter as Router, Route, Link } from "react-router-dom";
3+
4+
import Home from '../components/Home'
5+
6+
export default class HNRouter extends React.Component {
7+
render () {
8+
return (
9+
<Router>
10+
<div>
11+
<div className="nav">
12+
<ul>
13+
<Link to="/">Home</Link>
14+
<Link to="/page">Page</Link>
15+
<Link to="/about">About</Link>
16+
</ul>
17+
</div>
18+
19+
<Route exact path="/" component={Home}/>
20+
</div>
21+
</Router>
22+
)
23+
}
24+
}

0 commit comments

Comments
 (0)