React-js ignores label's 'for' attribute

JavascriptReactjs

Javascript Problem Overview


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

The following:

<label for="recipient-name" className="control-label">Recipient:</label>

is rendered as:

<label class="control-label">Recipient:</label>

on an unrelated note, i find it annoying that i can not change attributes using chrome's console when using React. is there a way around that? for example if i inspect the rendered element and add the 'for' attribute manually, it disappears when i click away from that control (presumably because react re-renders the control i'm guessing)

Javascript Solutions


Solution 1 - Javascript

You must use htmlFor attribute instead

<label htmlFor="recipient-name" className="control-label">Recipient:</label>

Solution 2 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmike01010View Question on Stackoverflow
Solution 1 - JavascriptzerkmsView Answer on Stackoverflow
Solution 2 - JavascriptAli RehmanView Answer on Stackoverflow