score:4

Accepted answer

you have to use onclick like this

onclick={()=>setselected(section)}

score:2

if you want to add a value to a function you should use an inline function inside the onclick. right now you are triggering the function for each rendering at render time.

change:

onclick={setselected(section)}

to:

onclick={() => setselected(section)}

Related Query

More Query from same tag