Add event handler to React.DOM element dynamically

前端 未结 4 542
无人及你
无人及你 2021-02-01 06:54

I\'m working with a RadioButtonGroup component which is like radio input but with buttons:

\"enter

4条回答
  •  孤街浪徒
    2021-02-01 07:25

    I would not like to add onClick handler to every button element

    React uses events delegation pattern, so you can freely adding as many onClick handlers as needs.

    Another way, if you just want to make code clear, you may create your own button component, and pass _onActiveChange to it props, but i don't sure that it's necessary in your case.

    And remember, that React works with synthetic events, and, in some cases, usage of setState within native event handlers may cause an unpredictable behaviour.

提交回复
热议问题