How do I detect in my class component which <input/>
's value
was clicked in my functional component? For example, if the user clicks Yes
, then I want the postIsClicked()
(which's in my class component) function to display that it's indeed detected the Yes
that's been clicked.
My attempt consisted of giving a name
to the inputs and then trying to detect is via e.target.name
but it just keeps loggin No has been clicked
in the console regardless of which button I press (Yes or No)
What am I doing wrong?
Pastebin below.
The onClick
function can receive the event as argument, so you can access the value by getting e.target.value
.
In your case you just need to receive event
as argument to postIsClicked(event)
and then console.log("clicked" + event.target.value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.