I have a following class
export default class TestInput extends Component {
state = {
modified: false
};
change = e => {
this.setState({ modified: true });
this.props.input.onChange(e.target.value);
};
render() {
return (
<input type="text" value={this.props.input.value} onChange={this.change} className={!this.state.modified && this.props.meta.pristine ? 'default' : 'modified'} />
);
}
}
that I'm using like this
<Field component={TestInput} name="testProp" />
Whenever I place a cursor in the middle of the text in the field and write a letter, the letter appears at the right place but the cursor jumps to the end of the field. This is caused by the line this.setState({ modified: true });
and subsequent class change. If I comment out this line, this is not happening. I don't understand it. What am I doing wrong? Can I do something about it?