#Show value onClick segmented control

5 messages · Page 1 of 1 (latest)

spark gust
#

Hi, how can I show a different value when clicking on a segment?
I've attached an example.
Instead of links, i want to show different forms

boreal moss
#

you need to adapt the code to do this

for example, the [active, setActive] should become two different states instead of one

e.g.
accountActive, setAccountActive
generalActive, setGeneralActive

you then need to refactor the const links with ternaries: change the item.label === active to check depending on section

item.label === (section === 'account' ? accountActive : generalActive)

and do the same in onClick

if (section === 'account')
setAccountActive(item.label)
else
setGeneralActive(item.label)

boreal moss
#

just use a ternary

#

{section === 'account' ? (
<AccountForm/> :
<GeneralForm/>
)}