Last active
December 28, 2018 18:26
-
-
Save ilonacodes/e77d21216e459a456fad5f723cc3f5ff to your computer and use it in GitHub Desktop.
This file contains 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
//ProgressBar.js; | |
// import hook func from react | |
import React, {useState} from 'react'; | |
... | |
export const ProgressBarContainer = () => { | |
// init state through hook func useState() | |
const [percentRange, setProgress] = useState(0); | |
return ( | |
<div className="container"> | |
{/*pass the percentageRange state to other components*/} | |
<ProgressBar percentRange={percentRange}/> | |
<div className="toggle-buttons"> | |
{/* call setProgress func on button click and bind the callback*/} | |
{/* depending on the percentageRange condition to decrease /*/} | |
{/* increase in 20% range and reset the progress bar status*/} | |
<button onClick={() => setProgress(percentRange > 0 ? percentRange - 20 : 0)}>Decrease</button> | |
<button onClick={() => setProgress(percentRange < 100 ? percentRange + 20 : 100)}>Increase</button> | |
<button onClick={() => setProgress(0)}>Reset</button> | |
</div> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment