Single handler on multiple listener on react

前端 未结 3 1770
陌清茗
陌清茗 2020-12-07 06:45

Were trying to use es6 to make dynamic state without multiple handlers but I\'m stuck. I\'ve no clue what\'s wrong with my code below

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 06:56

    In you case event delegation should help. Instead of binding multiple event handlers for every input, bind single one on the common parent container:

    Mon
    Tue

    Now in handleAdvancePrice you can check for proper event target, it should be input elements, i.e. e.target.tagName === 'INPUT', and proceed in this case. But if you don't have other form elements within this container, you don't even need this check, because onChange event can only originate from form elements and if you only have inputs, you are fine and handleAdvancePrice stays untouched.

提交回复
热议问题