Skip to content

Instantly share code, notes, and snippets.

View geetotes's full-sized avatar

Lee Gillentine geetotes

View GitHub Profile
class BasicWizard extends React.Component {
constructor() {
this.state = {
currentStep: 1
};
this._next = this._next.bind(this);
this._prev = this._prev.bind(this);
}
class BasicWizard extends React.Component {
constructor() {
this.state = {
steps: []
currentStep: location.hash //obvs this is an unsafe way to do this -- this example is for conceptual purposes only
};
}
// This keeps the hash updated when the user moves to the next step in the wizard
componentDidUpdate() {
class Step1 extends React.Component {
constructor(props) {
super(props);
// Bindings for form fields would go here,
// and state would keep track of field input
}
_validate() {
// a sanitized version of state can be passed instead
this.props.afterValid(this.state)
}
import React from 'react';
import { connect } from 'react-redux';
class PrettyLoader extends React.Component {
_show() {
// Don't forget that loading can be any data type you want!
if (this.props.loading === true) {
return (
<div className="loading">
<img src="crazyLoading.gif" />
@geetotes
geetotes / PrettyLoader-Pure.es6
Created March 25, 2017 19:45
PrettyLoader-Pure.es6
let PrettyLoader = (props) => {
let style={ 'hidden' : props.loading === true ? true : false }; // Or whatever way you want to toggle the content
return <PrettyLoader style={style}>{props.children}</PrettyLoader>;
};
class GenericControlledForm extends React.Component {
constructor() {
super();
this.state {
name: '',
occupation: ''
};
this._onChange = this._onChange.bind(this);
}
function filterMyArray(filterProperty) {
let _ = this.myArray.concat(); // safely copy myArray (which is an array of objects)
let filtered = _.filter((i) => {
return i.propery === filterPropery
});
return filtered;
}
class NeatoComponent extends React.Component {
constructor() {
super();
this.state = {
foo: this.props.foo,
bar: this.props.bar
};
}
componentWillReceiveProps(nextProps) {
class NeatoComponent extends React.Component {
constructor() {
super();
this.state = {
foo: this.props.foo,
bar: this.props.bar
}
}
render() {
class NeatoComponent extends React.Component {
render() {
// Guard clause
if (this.props.user === undefined) {
return null;
}
/*
* Actual render code here
*/
}