1.清空input输入框
class CustomTextInput extends React.Component {
constructor(props) {
super(props);
this.textInput = React.createRef();
}
clear() {
this.textInput.current.state.value = '';
}
render() {
return (
<Search size="large" defaultValue="" style={{ width: 400 }} ref={this.textInput} />
<Button onClick={() => {this.clear()}}>清空<Button>
);
}
}
2.react中select重新设置defaultValue
给select添加一个key,赋予不同值
select:
<Select
key={this.state.selectValue}
onChange={this.handleChange}
defaultValue='All Products'
style={{ width: 120 }}
>
<Option value='0'>All Products</Option>
<Option value='2'>Has Reviews</Option>
<Option value='1'>No Reviews</Option>
<Option value='3'>New Reviews</Option>
</Select>
js:
this.state = {
selectValue:0
};
this.setState({
selectValue:Math.random()*10
})