score:58

Accepted answer

check this link from react docs: react textarea value

basically for textarea react does not supports text enclosed within and you rather need to specify that as value or defaultvalue.

the right way thus is

<textarea name="description" value="this is a description." />

or

<textarea name="description" defaultvalue="this is a description." />

the difference with value and defaultvalue is that specifying defaultvalue leaves the component uncontrolled:

with an uncontrolled component, you often want react to specify the initial value, but leave subsequent updates uncontrolled. to handle this case, you can specify a defaultvalue attribute instead of value.

...while specifying value instructs react to control the component, meaning you need to update value property to make sure that change is reflected in the component:

since the value attribute is set on our form element, the displayed value will always be this.state.value, making the react state the source of truth.

to get a clear idea of difference between value / default value check this: fiddle for value default value distinction console will always show new value but component will not.

score:-4

i had the same problem. i solved it by using controlled component, e.g.

state.value = this.props.value 
<textarea value={this.state.value} onchange={handler} />

it works fine to control the input part. however, i had another issue, i need to init/change the state.value to props.value whenever there is a re-render.

i used the lift-cycle methods and it works perfect fine.

componentwillreceiveprops: function(){
    this.setstate({
        value: this.props.value
    }) }

hope this helps.

score:0

actually that is exactly what is wrong. from the docs:

if you want to initialize the component with a non-empty value, you can supply a defaultvalue prop.


Related Query

More Query from same tag