jsillitoe / react-currency-input

React component for inputing currency amounts
MIT License
203 stars 163 forks source link

dont work with hooks #101

Open patricklongo1 opened 4 years ago

patricklongo1 commented 4 years ago

if u try use hooks.. its do not works.

Ex: const [price, setPrice] = useState('');

<CurrencyInput decimalSeparator="," thousandSeparator="." prefix="R$ " onChangeEvent={(event, maskedvalue, floatvalue) => setPrice(floatvalue) } />

the input keep reseting... can someone try fix this?

colthreepv commented 4 years ago

use also value={price}

Full example:

<CurrencyInput decimalSeparator="," thousandSeparator="." precision="2" suffix=" €"
  value={price}
  selectAllOnFocus
  onChange={(_, val) => setPrice(val)}/>
patricklongo1 commented 4 years ago

use also value={price}

Full example:

<CurrencyInput decimalSeparator="," thousandSeparator="." precision="2" suffix=" €"
  value={price}
  selectAllOnFocus
  onChange={(_, val) => setPrice(val)}/>

Tks man! Its worked for me!

nazarenooviedo commented 4 years ago

Still not working for me, do you any comment? Thanks

patricklongo1 commented 4 years ago

Still not working for me, do you any comment? Thanks

My full code for this lib: https://github.com/patricklongo1/gympoint-web/blob/master/src/pages/PlanRegister/index.js

@important: import CurrencyInput from 'react-currency-input'; const [priceMonth, setPriceMonth] = useState('');

function handleInput(floatvalue) { setPriceMonth(floatvalue); }

return ( < div > < span >PREÇO MENSAL< /span > < CurrencyInput thousandSeparator="." decimalSeparator="," precision="2" prefix="R$ " value={priceMonth} selectAllOnFocus onChange={(_, floatvalue) => handleInput(floatvalue)} / > < /div > )

Hope its help u!

nazarenooviedo commented 4 years ago

Thank so much!, I will try it 👍

ericblade commented 3 months ago

https://github.com/ericblade/react-currency-input/issues/15