Created
April 30, 2017 21:59
-
-
Save geetotes/8de877d46dcc8288aa8978e4b58da4a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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