I am creating my edit form with react-redux. Until now, I can get the data of the item that I want to change, but I do not know how to pre-populate the input value, and to be able to change it. Because when I try to tape something in the input, the text does not change.
So, how can I pre-populate the input value, and being able to tape into it.
import React from 'react';
import PropTypes from 'prop-types';
class EditTodoComponent extends React.Component {
state = {
text: this.props.todo.text
}
onChange(e) {
this.setState({ text: e.target.value });
}
render() {
return(
<div>
<form>
<input type="text" value={this.state.text} onChange={this.onChange}/>
</form>
</div>
);
}
}
EditTodoComponent.propTypes = {
todo: PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired
}).isRequired,
visible: PropTypes.bool.isRequired
}
export default EditTodoComponent