Skip to content

Instantly share code, notes, and snippets.

@geetotes
Created April 30, 2017 21:59
Show Gist options
  • Save geetotes/8de877d46dcc8288aa8978e4b58da4a7 to your computer and use it in GitHub Desktop.
Save geetotes/8de877d46dcc8288aa8978e4b58da4a7 to your computer and use it in GitHub Desktop.
class BasicWizard extends React.Component {
constructor() {
this.state = {
currentStep: 1
};
this._next = this._next.bind(this);
this._prev = this._prev.bind(this);
}
_next() {
let currentStep = this.state.currentStep;
// Make sure currentStep is set to something reasonable
if (currentStep >= 2) {
currentStep = 3;
} else {
currentStep = currentStep + 1;
}
this.setState({
currentStep: currentStep
});
}
_prev() {
let currentStep = this.state.currentStep;
if (currentStep <= 1) {
currentStep = 1;
} else {
currentStep = currentStep - 1;
}
this.setState({
currentStep: currentStep
});
}
render() {
return(
<div>
<Step1 currentStep={currentStep} />
<Step2 currentStep={currentStep} />
<Step3 currentStep={currentStep} />
<button onClick={this._next}>Next</button>
<button onClick={this._prev}>Prev</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment