Skip to content

Instantly share code, notes, and snippets.

View jwill9999's full-sized avatar
💭
working

Jason Williams jwill9999

💭
working
View GitHub Profile
@jwill9999
jwill9999 / webpack.config.js
Created February 24, 2017 22:15
Reactjs Webpack Dev Server
var webpack = require("webpack");
module.exports = {
entry: "./src/js/index.js",
output: {
path: "dist/assets",
filename: "bundle.js",
publicPath: "assets"
},
devServer: {
@jwill9999
jwill9999 / package.json
Created February 24, 2017 22:17
React Redux Package.json Template
{
"name": "react_redux_template",
"version": "1.0.0",
"description": "A Template React and Redux",
"main": "./dist",
"scripts": {
"start": "./node_modules/.bin/webpack-dev-server",
"build": "weback",
"prod": "webpack -p"
},
@jwill9999
jwill9999 / App.js
Last active February 24, 2017 22:21
React Router file with Root file input(example)
import React from 'react';
import UserList from '../containers/user-list';
import UserDetails from '../containers/user-detail';
import Nav from './Nav/Nav'
require('../../scss/style.scss');
class Root extends React.Component {
render() {
@jwill9999
jwill9999 / localStorage.js
Created February 26, 2017 00:35
Persisting State to localStorage Redux React
import throttle from 'lodash/throttle';
export const loadState = () => {
try {
const serializedState = localStorage.getItem('state');
if(serializedState === null) ? return undefined : return JSON.parse(serializedState)
}
catch(err) {
return undefined
};
@jwill9999
jwill9999 / index.js
Created February 26, 2017 00:38
Create New Individual Id React
import { v4 } from 'node-uuid';
*******EXAMPLE BELOW**********
export const addTodo = (text) => ({
type: 'ADD_TODO',
id: v4()
})
@jwill9999
jwill9999 / index.js
Last active February 26, 2017 01:29
React Events
/* preventing default behaviour */
function ActionLink() {
function handleClick(e) {
e.preventDefault();
console.log('The link was clicked.');
}
return (
@jwill9999
jwill9999 / example1.js
Created February 26, 2017 01:38
React Conditional Rendering
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in.
</div>
);
}
@jwill9999
jwill9999 / SelectTag.js
Created February 26, 2017 01:56
React Forms Management
class FlavorForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: 'coconut'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
@jwill9999
jwill9999 / asyncValidate.js
Last active February 26, 2017 18:22
React Form example with Material-UI
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const asyncValidate = (values/*, dispatch */) => {
return sleep(1000) // simulate server latency
.then(() => {
if ([ 'foo@foo.com', 'bar@bar.com' ].includes(values.email)) {
throw { email: 'Email already Exists' }
}
})
}
@jwill9999
jwill9999 / index.js
Created March 6, 2017 22:40
React Local storage
const initialState = (localStorage["redux-store"]) ?
JSON.parse(localStorage["redux-store"]) :
sampleData
const saveState = () =>
localStorage["redux-store"] = JSON.stringify(store.getState())
// createStore here
store.subscribe(saveState)