I am trying to capture the moment when the user stops typing in the controlled input. It happens so smooth inside the uncontrolled component.
When I have tried with setTimeout
, only the last character came as an input rest all were not inputted. I am not sure why it happened
import React, { Component } from "react";
import ReactDOM from "react-dom";
import {connect} from 'react-redux';
import "./styles.css";
class Main extends Component{
state={}
timeout = null;
onChange = e => {
this.props.handleInputChange(e.target.value);
}
render(){
return (
<div className="Main">
<input type='text' value={this.props.val} onChange={this.onChange}/>
</div>
);
}
}
const mapStateToProps = state => {
val: state.reducer.val
}
const mapDispatchToProps = dispatch => {
handleInputChange: (val)=>dispatch(reducer.changeInput(val))
}
connect(mapStateToProps,mapDispatchToProps)(Main);
when User stops typing, it should dispatch changeInput
action