1

I am working on Update Task activity, and I am not able to edit content in Textbox as it has been derived from this.props.location.state.****.

Please suggest. How I can keep it editable.

Code :

<textarea ref="taskdescr" type="text" class="form-control" value={this.props.location.state.tskDescr} id="taskDesc"></textarea>

enter image description here

rrk
  • 15,677
  • 4
  • 29
  • 45
Sameer Patkar
  • 101
  • 1
  • 9

3 Answers3

0

This is normal because when you provide value props in react.

The textarea will gain the value your provided after each render.

So because the value of your props does not change when you edit the textarea, the provided value is always the same.

To make your textarea editable your need to use the state instead of props.

If i understand what you want to do your state can look like site

{
  tskDescr: '',
  proptskDescr: '',
}

Use getDerivedStateFromProps and update tskDescr when proptskDescr is not equal to props.location.state.tskDescr.

And add an onChange event on the textarea to update the tskDescr

0

You need to change the value on the state using onChange for the textarea as follows

constructor(props){
    super(props);
    this.state = {
        location: {
            tskDescr: ''
        }
    }
}

And then

handleChange = (event) => {
    this.setState({
        location: {
            tskDescr: event.target.value
        }
    });
}
Shrikantha Budya
  • 646
  • 1
  • 4
  • 15
Syed
  • 540
  • 7
  • 21
0

Props are immutable use state if you want to mutate the values, after adding the state you need to provide a listener so that you can change the value.

<textarea
    value={this.state.text}
    onChange={this.handle}
/>

handle = ({target:{value}}) => this.setState({text:value});

Shrikantha Budya
  • 646
  • 1
  • 4
  • 15