Reputation: 189
Not sure if this is React specific, but, why does the following work in React and render some text to the element:
<textarea value="Some text."></textarea>
but the same in plain HTML does not:
<textarea value="Some text."></textarea>
maybe I am missing something or done something foolish? Apologies and thanks in advance!
Upvotes: 2
Views: 775
Reputation: 944442
The textarea
child content represents the default value of a text area, but the value
property represents the current value.
It is the current value that needs to be manipulated via JS, not the default value.
Upvotes: 1
Reputation: 203466
In HTML the text
area is a non-self-closing tag and has content. It defines its text by children.
<textarea id="story" name="story" rows="5" cols="33">
It was a dark and stormy night...
</textarea>
In React it uses the value
attribute. Note that is also self-closing and takes no children.
This keeps the textarea
element consistent with other form elements such as input
and select
.
<textarea
id="story"
name="story"
rows="5"
cols="33"
value="It was a dark and stormy night..."
/>
Upvotes: 1