我试图捕捉用户停止输入受控输入的那一刻。它在不受控制的组件内部发生得如此顺利。
当我尝试使用时setTimeout
,只有最后一个字符作为输入,其余的都没有输入。我不确定为什么会这样
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);
当用户停止输入时,它应该调度changeInput
动作