I have made currency input mask:
let resultArr = value.split("").map((x) => {
return !isNaN(+x) && x !== " " ? "n" : "";
});
resultArr = resultArr.join("").replace(/\B(?=([n]{3})+(?![n]))/g, ","); //1234 => nnnn, 1234 => 123,4
return "$" + `${resultArr}\rn`;
where value is the value of input (https://codesandbox.io/s/suspicious-currying-68cl8?file=/index.js), but there is the error Maximum update depth exceeded. I find out that's because of \r code in my input mask. How can I fix this error?