const valueRef = React.useRef<HTMLInputElement>(null);
const CurrencyInput = () => {
const [focus, setFocus] = React.useState<boolean>(false);
return (
<>
<CurrencyContainer
onClick={() => valueRef.current?.focus()}
isFocused={focus}
>
<CurrencyInput
type="number"
value={storage.updatesomevalue}
onChange={e => dispatch(updatesomevalue(parseInt(e.target.value)))}
ref={valueRef}
onFocus={() => setFocus(true)}
onBlur={() => setFocus(false)}
/>
<Currency>USD</Currency>
</CurrencyContainer>
</>
);
};
<CurrencyContainer> is a styled div, CurrencyInput is a styled input, and <Currency> is a styled p.
I found the perfect behavior I'm looking for within this question here (I don't need the dollar sign) but haven't been able to integrate it within my existing code. Format currency input field with dollar sign & commas
Could someone please help me implement this within my typescript react function?
Edit: A lot of people have asked what I'm trying to do ... I'm trying to make sure the numbers into the currency input are comma separated for visibility. I want 1000000 to be visible as 1,000,000.