React Checkbox not sending onChange

后端 未结 7 1402
夕颜
夕颜 2020-12-04 16:19

TLDR: Use defaultChecked instead of checked, working jsbin.

Trying to setup a simple checkbox that will cross out its label text when it is checked. For some reason

7条回答
  •  心在旅途
    2020-12-04 16:44

    It's better not to use refs in such cases. Use:

    
    

    There are some options:

    checked vs defaultChecked

    The former would respond to both state changes and clicks. The latter would ignore state changes.

    onClick vs onChange

    The former would always trigger on clicks. The latter would not trigger on clicks if checked attribute is present on input element.

提交回复
热议问题