Skip to content

Instantly share code, notes, and snippets.

View aofleejay's full-sized avatar
🐢
Keep going

aofleejay

🐢
Keep going
View GitHub Profile
@aofleejay
aofleejay / integration.test.js
Created October 11, 2017 13:09
GraphQL integration test
import { expect } from 'chai'
import supertest from 'supertest'
import server from '../../src/server'
describe('Test query', () => {
it('has correct getCharacters query', (done) => {
const request = supertest.agent(server)
const query = {
query: `
query {
@aofleejay
aofleejay / localStorage.js
Created February 17, 2018 15:06
localStorage module
const loadState = () => {
try {
const serializedState = localStorage.getItem('store')
if (serializedState === null) {
return undefined
} else {
return JSON.parse(serializedState)
}
} catch (error) {
return undefined
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:09
Config redux store with local storage
import { createStore } from 'redux'
import rootReducer from '../reducers'
import { loadState, saveState } from '../lib/localStorage'
const persistStore = loadState()
const store = createStore(rootReducer, persistStore)
store.subscribe(() => {
saveState(store.getState())
})
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:12
Config store with redux-persist
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import rootReducer from '../reducers'
const persistConfig = {
key: 'root',
storage,
}
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:13
Use redux-persist with react
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'
import App from './components/App'
import configureStore from './store'
const { store, persistor } = configureStore()
ReactDOM.render(
@aofleejay
aofleejay / index.js
Created February 17, 2018 15:18
Redux-persist blacklist & white list
const persistConfig = {
key: 'root',
storage: storage,
blacklist: ['language'] // whitelist: ['language']
};
@aofleejay
aofleejay / App.js
Last active February 23, 2018 09:18
Try React-Native Gesture
import React from 'react'
import { StyleSheet, Text, View, PanResponder } from 'react-native'
export default class App extends React.Component {
state = {
top: 0,
left: 0,
topTransition: 0,
leftTransition: 0,
}
@aofleejay
aofleejay / index.html
Last active May 17, 2018 18:07
Simple React boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
@aofleejay
aofleejay / index.html
Created May 17, 2018 09:36
Simple React boilerplate with Babel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="root"></div>
import React, { Component } from 'react'
import { Form, Input } from 'antd'
class App extends Component {
handleSubmit = (e) => {
e.preventDefault()
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
}