I have made a tab-component and a progressbar with 3 tabs. When i select the first tab i want my progressbar to be at 33%, second tab 66% and third 100%.
I need some help figuring out how to make my progress-bar change it’s value when i change tabs. The progress-meter fills up when you give a value of 0-100 in the component props.
So.. should i use redux to track the value or what do you guys suggest. Thanks a billion
Advertisement
Answer
You can just set the progress value in the state on click of the tab items like below
JavaScript
x
15
15
1
function TabProgress() {
2
let [progress, setProgress] = useState(0);
3
return (
4
<>
5
<ul>
6
<li className="xxx" onClick={() => setProgress(100 / 3)}>A</li>
7
<li className="xxx" onClick={() => setProgress(100 / 2)}>B</li>
8
<li className="xxx" onClick={() => setProgress(100 / 1)}>C</li>
9
</ul>
10
<ProgressBar width="xxx" value={progress} />
11
</>
12
)
13
}
14
15
You can also render <li>
dynamically to create a proper component
JavaScript
1
6
1
<ul>
2
{props.tabs.map((tab, i) => (
3
<li className="xxx" key={tab} onClick={() => setProgress(100 / props.tabs.length - i)}>{tab}</li>
4
))}
5
</ul>
6