I've been working on a simple calculator app and I want commas to be displayed on the output. How do I go about it.
const [result, setResult] = useState("");
const handleClick = (e) => {
setResult(result.concat(e.target.name));
};
const calculate = () => {
try {
setResult(eval(result).toString());
} catch (err) {
setResult("Error");
}
};
I tried console logging the result with the .toLocaleString('en-US') method but it still doesn't work.
console.log(result.toLocaleString('en-US'))