Reactjs 状态更改后需要TextField更新文本
我需要对文本字段做一个小更改。基本上有一个重置按钮,用于清除搜索。用户可以在文本字段中写入搜索字符串。但是clear函数只重置实际搜索,而不是TextField,后者仍然包含用户编写的某种搜索字符串Reactjs 状态更改后需要TextField更新文本,reactjs,typescript,Reactjs,Typescript,我需要对文本字段做一个小更改。基本上有一个重置按钮,用于清除搜索。用户可以在文本字段中写入搜索字符串。但是clear函数只重置实际搜索,而不是TextField,后者仍然包含用户编写的某种搜索字符串 接口抽屉容器rops{ dataProfile:dataProfile; } 接口DroperContainerComponentProps使用StibStyles和命名空间扩展了DroperContainerProps{ } 接口抽屉容器状态{ attributeSearchText:字符串;
接口抽屉容器rops{
dataProfile:dataProfile;
}
接口DroperContainerComponentProps使用StibStyles和命名空间扩展了DroperContainerProps{
}
接口抽屉容器状态{
attributeSearchText:字符串;
}
类ProfileDroperContainerComponent扩展了React.Component{
只读状态:只读={
attributeSearchText:“
};
setAttributeSearchText=debounce((searchText)=>this.setState({attributeSearchText:searchText}),200);
onSearch=(事件:React.ChangeEvent)=>this.setAttributeSearchText(事件.目标.值);
clearSearch=()=>this.setAttributeSearchText(“”);
render(){
const{classes,dataProfile,t}=this.props;
返回(
{t(“drawer.objectType”,{defaultValue:“对象类型筛选器”}
{dataProfile&&}
{t(“drawer.attributes”,{defaultValue:“attributes”}
);
}
}
您需要“控制”文本字段的值。就是
<TextField
id="attribute-search"
placeholder={t("drawer.search", { defaultValue: "Search" })}
type="search"
className={classes.searchField}
onChange={this.onSearch }
value={this.state.attributeSearchText}
/>
很抱歉把答案弄得一团糟,在电话里写合法的答案真的很难。我最后只是走到我的电脑前,然后完成它。