I want to remove data once the clear button is clicked. so for that i have set the state with empty array using data:[]
. when i console log it, it gives me an empty array which means the state is updating. but the moment it goes here this.props.form.setFieldsValue
line. the state is again updating with the old values (props values).
if anyone know how to fix this please tell. thanks
Clear = async () => {
await this.setState({
textOne: 0,
texttwo: 0,
textthree: 0,
data:[]
});
this.props.form.setFieldsValue({
number_field_one: '',
});
}
<div style={{ width: "100%", marginTop: "3%", marginBottom: "1%" }}>
<span>
{getFieldDecorator("number_field_one", {})(
<Select
onChange={e => {
this.setState({ ID: e });
}}
filterOption={(input, option) =>
option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
>
{Options}
</Select>
)}
</span>
{this.state.data ? (
<div
style={{ float: "right", width: "30%", height: 280, overflowY: "scroll" }}
>
<List
loading={this.props.loading}
size="small"
bordered
dataSource={this.state.data}
renderItem={item => <List.Item>{item}</List.Item>}
/>
</div>
) : (
<div
style={{ float: "right", width: "30%", height: 280, overflowY: "scroll" }}
>
<List
loading={this.props.loading}
size="small"
bordered
dataSource={data}
renderItem={item => <List.Item>{item}</List.Item>}
/>
</div>
)}
</div>
<Button onClick={this.Clear} type="danger" >Clear</Button>