when i am trying to change the state of input field using onchange e.target.value is giving the value before change
<form onSubmit={this.handleSubmit}>
<input type='text'value={this.state.search} onChange={this.onChange}/>
<button type='submit' >Search</button>
</form>
the onchange function looks like this
onChange=(e)=>{ var search=e.target.value;
this.setState({search})
this.props.dispatch({type:'SUGG',payload:this.state.search,})
}
I tried logging both e.target.value
and this.state.search
e.target.value is showing correct value but state is showing previous value
edit: I got it setstate is async function so the previous value is getting logged