When the App starts, the button's text is initially 'c'. When the button is clicked, it goes to toggleDisplay() and checks if unit === 'c'. If it's true, then update the unit variable to 'f'. This part works as I tested it using console.log. But the unit variable that in inside <button> tag is not updating. It's only showing 'c' but it has to toggle between 'c' and 'f'
function App() {
...
...
let unit = "c";
const toggleDisplay = () =>{
if(unit === 'c'){
unit = "f";
console.log(unit)
}
else{
unit = "c";
console.log(unit)
}
}
return(
<button className="temp" onClick={toggleDisplay}>
{unit}
</button>
)
Ps. This is actually a weather app and the toggle between 'c' and 'f' is the toggle between values of celsius and fahrenheit.
unitin state?