How to put the default value for textarea in React | Put state value as default value.

Put the default value for textarea in React

To Put default value , include ‘defaultvalue’ attribute in textarea tag & put any value you want as default in double inverted comma like –

<textarea
   id="markdown-content"
   onChange={this.handleChange}
   defaultValue="90"
/>

Here 90 is default value , so whenever textarea will display on web page , 90 will be there like –

Put state value as default value

You need state defined & some values under it to put it as default value.

Suppose , We have state defined as –

constructor(props) {
    super(props);

    this.handleChange = this.handleChange.bind(this);
    this.state = { title: 'javaatpoint' };
  }

When the state is defined , than you have to include state value as default value in text area like –

<textarea
  id="markdown-content"
  onChange={this.handleChange}
  defaultValue={this.state.title}
 />

In above code , this.state.title is accessing the title value defined in state.

It’s Output be like –