diff --git a/source/components/CurrencyInput/CurrencyInput.js b/source/components/CurrencyInput/CurrencyInput.js index d12fab4d0..2dcd46ccc 100644 --- a/source/components/CurrencyInput/CurrencyInput.js +++ b/source/components/CurrencyInput/CurrencyInput.js @@ -21,19 +21,20 @@ let currencyFormat = language => ({ .charAt(1) }) -function CurrencyInput({ - value, +export default function CurrencyInput({ + value: valueArg, debounce: debounceTimeout, onChange, language, className, ...forwardedProps }) { - const [currentValue, setCurrentValue] = useState(value) - const [initialValue] = useState(value) + const [currentValue, setCurrentValue] = useState(valueArg) + const [initialValue] = useState(valueArg) + // When the component is rendered with a new "value" argument, we update our local state useEffect(() => { - setCurrentValue(value) - }, [value]) + setCurrentValue(valueArg) + }, [valueArg]) const nextValue = useRef(null) const onChangeDebounced = useRef( debounceTimeout ? debounce(debounceTimeout, onChange) : onChange @@ -62,10 +63,10 @@ function CurrencyInput({ } = currencyFormat(language) // We display negative numbers iff this was the provided value (but we allow the user to enter them) - const valueHasChanged = value !== initialValue + const valueHasChanged = currentValue !== initialValue // Autogrow the input - const valueLength = (value || '').toString().length + const valueLength = (currentValue || '').toString().length return (
) } - -export default CurrencyInput