I am learning functional components with React and I have a simple code, which returns 'Nah' when the state value is 0.
The problem is that this doesn't work during render. Why is that?
import React, { useState } from "react";
import { Button } from "react-bootstrap";
const Counter = () => {
const [count, setCount] = useState(0);
const formatCount = () => {
count === 0 ? setCount("Nah") : setCount(0);
};
// let classes = "badge m-2";
// classes += (this.state.count === 0) ? "badge-warning" : "badge-primary";
return (
<div>
<Button className="badge badge-warning m-2">-</Button>
{this.formatCount()}
<button>+</button>
</div>
);
};
export default Counter;