score:2

Accepted answer

you have to create an arrow function as such:

onchange={()=>console.log(item.option_image.alt)}

what you are doing now is simply accessing the onchange method.

notice the difference:

with onchange={(e) => onchange(e)}, you are essentially creating a new function that calls onchange method during each render.

with onchange={onchange}, you are directly accessing onchange method.

score:1

you need to do it like this:

                onchange={() => console.log(item.option_image.alt)}

if you don't do it like this, it will run the console on the first load of the page, not when the radio is clicked.


Related Query

More Query from same tag