setup firebase
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { Component } from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
import React, { Component } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
import User from "./components/User.js";
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
@@ -19,6 +20,7 @@ class App extends Component {
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
<User />
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
|
||||
43
src/components/User.js
Normal file
43
src/components/User.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import React from "react";
|
||||
import fire from "../fire.js";
|
||||
|
||||
class User extends React.Component {
|
||||
state = {
|
||||
name: ""
|
||||
};
|
||||
|
||||
updateInput = e => {
|
||||
this.setState({
|
||||
[e.target.name]: e.target.value
|
||||
});
|
||||
};
|
||||
|
||||
addUser = e => {
|
||||
e.preventDefault();
|
||||
const db = fire.firestore();
|
||||
db.settings({
|
||||
timestampsInSnapshots: true
|
||||
});
|
||||
const userRef = db.collection("users").add({
|
||||
name: this.state.name
|
||||
});
|
||||
this.setState({ name: "" });
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<form onSubmit={this.addUser}>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
placeholder="Name"
|
||||
onChange={this.updateInput}
|
||||
value={this.state.name}
|
||||
/>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
||||
14
src/fire.js
Normal file
14
src/fire.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import firebase from "firebase";
|
||||
const FIREBASE_API_KEY = process.env.REACT_APP_FIREBASE_API_KEY;
|
||||
|
||||
const config = {
|
||||
apiKey: FIREBASE_API_KEY,
|
||||
authDomain: "journal-app-service.firebaseapp.com",
|
||||
databaseURL: "https://journal-app-service.firebaseio.com",
|
||||
projectId: "journal-app-service",
|
||||
storageBucket: "journal-app-service.appspot.com",
|
||||
messagingSenderId: "492083585165"
|
||||
};
|
||||
const fire = firebase.initializeApp(config);
|
||||
|
||||
export default fire;
|
||||
Reference in New Issue
Block a user