In React (Facebook's framework), I need to render a label element bound to a text input using the standard for
attribute.
e.g. the following JSX is used:
<label for="test">Test</label>
<input type="text" id="test" />
However, this produces HTML missing the required (and standard) for
attribute:
<label>Test</label>
<input type="text" id="test">
What am I doing wrong?
Yes, for react,
for
becomes htmlFor
class
becomes className
etc.
see full list of how HTML attributes are changed here:
both for
and class
are reserved words in JavaScript this is why when it comes to HTML attributes in JSX you need to use something else, React team decided to use htmlFor
and className
respectively
htmlFor
to replace for
!you can find more info by following the below links.
https://facebook.github.io/react/docs/dom-elements.html#htmlfor
For React you must use it's per-define keywords to define html attributes.
class
->className
is used and
for
->htmlFor
is used, as react is case sensitive make sure you must follow small and capital as required.
That is htmlFor in JSX and class is className in JSX
Source: Stackoverflow.com