Skip to content

Instantly share code, notes, and snippets.

View thedevdavid's full-sized avatar
🎯
Focusing

David thedevdavid

🎯
Focusing
View GitHub Profile
@thedevdavid
thedevdavid / store.js
Created February 26, 2018 10:25
store.js
import { createStore, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import ReduxThunk from 'redux-thunk';
import logger from 'redux-logger';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import rootReducer from '../reducers';
const middlewares = [ReduxThunk];
@thedevdavid
thedevdavid / App.js
Last active December 8, 2017 12:25
Helper functions
onLogin = async () => {
try {
const response = await firebase.auth().signInWithEmailAndPassword(this.state.emailValue, this.state.passwordValue);
console.log(response);
this.setState({
loggingIn: false,
emailValue: '',
passwordValue: '',
hasError: false,
error: '',
@thedevdavid
thedevdavid / App.js
Last active December 8, 2017 11:23
Auth mods
constructor() {
super();
this.ref = firebase.firestore().collection('posts');
this.firestoreUnsubscriber = null;
this.authUnsubscriber = null;
this.state = {
posts: [],
loading: true,
loggingIn: false,
user: null,
@thedevdavid
thedevdavid / App.js
Created December 7, 2017 15:05
Add random post method
addRandomPost = () => {
this.ref.add({
title: 'Added post by random button',
likes: Math.floor((Math.random() * 10) + 1),
uri: `https://picsum.photos/200/300?image=${Math.floor((Math.random() * 100) + 1)}`,
});
}
@thedevdavid
thedevdavid / App.js
Created December 7, 2017 14:46
App.js real-time Firestore implementation
constructor() {
super();
this.ref = firebase.firestore().collection('posts');
this.unsubscribe = null;
this.state = {
posts: [],
loading: true,
};
}