React-js ignores label's 'for' attribute

后端 未结 2 1087
深忆病人
深忆病人 2021-02-04 23:24

I know that for \'class\' we must use className, but how do i get react to preserve \'for\' attribute?

The following:

相关标签:
2条回答
  • 2021-02-04 23:32

    You must use htmlFor attribute instead

    <label htmlFor="recipient-name" className="control-label">Recipient:</label>
    
    0 讨论(0)
  • 2021-02-04 23:44

    for is a keyword in javascript so in JSX you can't use it. You must use htmlFor which is translated into for attribute once it is rendered to the DOM.

    0 讨论(0)
提交回复
热议问题