admin管理员组

文章数量:1391951

What is the best practice for handling events on Radio Buttons and Check boxes in ReactJS? The documentation shows using "onClick" on the "Handling Events" documentation and it shows using "onChange" in the "Forms" documentation. onChange only fires one time on Radio Buttons, so I am currently using onClick for them. I assume this is a bug.

What is the best practice for handling events on Radio Buttons and Check boxes in ReactJS? The documentation shows using "onClick" on the "Handling Events" documentation and it shows using "onChange" in the "Forms" documentation. onChange only fires one time on Radio Buttons, so I am currently using onClick for them. I assume this is a bug.

Share Improve this question asked Aug 2, 2017 at 14:06 LambertLambert 2,4436 gold badges31 silver badges44 bronze badges 1
  • 1 Regarding radio buttons, check out Radio Input onChange only fires once? – Kevin Commented Aug 2, 2017 at 14:09
Add a ment  | 

2 Answers 2

Reset to default 4

Heyo, It's not a bug it is because in some cases you only want to know when it changes. For example, when you have an API that supports patch so you can send modifications on every change.

If your API only support submitting all at once the onClick is right for you!

Radio buttons respond to both onchange and onclick events in JavaScript. However, the onchange event may not work as you would expect it. The onchange event is not triggered when turning a radio button on and off but only one or the other.

Most browsers trigger onchange when the radio button is selected, but Internet Explorer prior to version 9 triggers onchange when the radio button is deselected.

本文标签: javascriptonChange or onClick for Radio buttons and Check boxes in ReactJSStack Overflow