diff --git a/src/components/AmountForm.tsx b/src/components/AmountForm.tsx index 59260a3cbd78..a102b715d526 100644 --- a/src/components/AmountForm.tsx +++ b/src/components/AmountForm.tsx @@ -117,10 +117,10 @@ function AmountForm( const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(newAmountWithoutSpaces); const isForwardDelete = currentAmount.length > strippedAmount.length && forwardDeletePressedRef.current; - setSelection((prevSelection) => getNewSelection(prevSelection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length)); + setSelection(getNewSelection(selection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length)); onInputChange?.(strippedAmount); }, - [amountMaxLength, currentAmount, decimals, onInputChange], + [amountMaxLength, currentAmount, decimals, onInputChange, selection], ); // Modifies the amount to match the decimals for changed currency. diff --git a/src/components/BigNumberPad.tsx b/src/components/BigNumberPad.tsx index d01519a13513..4704ca6c6eec 100644 --- a/src/components/BigNumberPad.tsx +++ b/src/components/BigNumberPad.tsx @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, {useEffect, useRef, useState} from 'react'; import {View} from 'react-native'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -33,6 +33,11 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i const styles = useThemeStyles(); const [timer, setTimer] = useState(null); const {isExtraSmallScreenHeight} = useWindowDimensions(); + const numberPressedRef = useRef(numberPressed); + + useEffect(() => { + numberPressedRef.current = numberPressed; + }, [numberPressed]); /** * Handle long press key on number pad. @@ -46,7 +51,7 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i longPressHandlerStateChanged(true); const newTimer = setInterval(() => { - numberPressed(key); + numberPressedRef.current?.(key); }, 100); setTimer(newTimer);