I have one form component, in which we have one input field.once user enter a digit to input field and press submit, it should become two time of that input value.
import {Field} 'redux-form';
class Multiply extends React.Component {
onInputChange = (stateKey) => (e) => {
this.setState({ [stateKey]: e.currentTarget.value.trim() });
};
onSubmit = () => {
this.setState({ volume: this.state.volume *2 });
};
render(): JSX.Element {
return (
<div>
<div>
<form onSubmit={this.props.handleSubmit(this.onSubmit)}>
<Field
name="volume"
placeholder="Volume"
component={renderInput}
type="number"
value={this.state.volume}
onChange={this.onInputChange('volume')}
validate={required}
/>
<div>
<button type="submit">
Multiply by 2
</button>
</div>
</form>
</div>
</div>
);
}
}
once i click on button, value doesn't get change. but instead of <field> if i use <input> then it works fine. why ?