97
rated 0 times
[
100]
[
3]
/ answers: 1 / hits: 9309
/ 3 Years ago, sat, july 25, 2020, 12:00:00
I would like to add on a input a thousand separator using React Hooks but I'm not sure how. I have tried the below code so far and is not working.
Can you please point out what could be the issue and how can I implement this?
Thank you.
const MainComponent = () => {
const [value, setValue] = useState(0);
const numberWithComma = () => {
return (+value).toFixed(2).replace(/(d)(?=(d{3})+(?!d))/g, '$1,')
}
return (
<div>
<input
type="number"
onChange={numberWithComma}
placeholder="0"
/>
</div>
);
}
More From » reactjs