Olá, estou tentando "popular" um textarea com um valor, mas quando tento editar o campo e ele não permite. Já tentei utilizar a propriedade "defaultValue" mas o campo fica vazio. Segue partes do codigo:
class TaskForm extends React.Component {
constructor(props) {
super(props);
this.apis = new APIs();
this.state = {
taskEdit: [],
title: '',
description: '',
project: '',
service: '',
date: moment(),
};
}
componentDidMount() {
this.setState({ isLoading: true });
this.apis.editTask(this.props.location.state.id)//usar isso aqui
.then(taskEdit => {
return this.setState({
taskEdit: taskEdit ? taskEdit : {},
isLoading: false
});
});
}
handleChange(event) {
this.setState({[event.target.name]: event.target.value});
}
render() {
const { taskEdit } = this.state;
const { history } = this.props;
return (
<Layout history={history} styleName='container'>
<aside>
{taskEdit.title}
{taskEdit.description}
</aside>
<main>
<h1>{this.state.id}</h1>
<form onSubmit={this.handleSubmit}>
<h2>Edit Task</h2>
<br/>
<span>
Title:
<input defaultValue={taskEdit.title} type="text" size="100" className='title' name='title' onChange={this.handleChange}/>
</span>
<br/>
<br/>
<span>
Description:
<textarea value={taskEdit.description} type="text" className='description' name='description' onChange={this.handleChange}/>
</span>
<br/>
<br/>
</form>
</main>
<aside>
</aside>
</Layout>
);
}
}
export default TaskForm;
<textarea>
não suporta o value atributo.