JavaScript
x
14
14
1
<Form.Item
2
label="Amount"
3
name={[index, 'amount']}
4
>
5
<InputNumber
6
style={{ width: '100%' }}
7
min={1}
8
// onChange={() => {
9
// const array = [...form.getFieldValue('bankAccount')]
10
// setCurrentAccountArray(array)
11
// }}
12
/>
13
</Form.Item>
14
in the code above you can see that I am forcefully updating the state of currentAccountArray, I want to execute this after the value is completely changed instead of onChange, which executes on every key press…
is there a way I can achieve this? I do not want to use onEnterPressed.
Advertisement
Answer
Maybe use onInput instead of onChange? — OR — Maybe a delayed call wrapped in a closure?
JavaScript
1
29
29
1
function setCurrentAccountArray(arr){
2
// whatever your doing here
3
console.log("hi", arr)
4
}
5
6
var TO_later;
7
function delayedCall(fn, arg, delay){
8
clearTimeout(TO_later);
9
TO_later = setTimeout((function(Vfn, Varg){
10
return function(){
11
Vfn(Varg);
12
}
13
})(fn, arg), delay);
14
}
15
16
<Form.Item
17
label="Amount"
18
name={[index, 'amount']}
19
>
20
<InputNumber
21
style={{ width: '100%' }}
22
min={1}
23
onChange={() => {
24
const array = [form.getFieldValue('bankAccount')]
25
delayedCall(setCurrentAccountArray, array, 300)
26
}}
27
/>
28
</Form.Item>
29