useState in React - creating state to track the click of a button?

https://codesandbox.io/p/sandbox/musing-bash-5hdgh5?embed=1&file=%2Fsrc%2FApp.jsx%3A11%2C31 "Add a new state variable to keep track of the number of times the background color has been changed. Display the number of times the background color has been changed on the page." So far I have gotten as far as
const [timesClicked, setTimesClicked] = useState(0);
const [timesClicked, setTimesClicked] = useState(0);
Now I think I have to put use setTimesClicked in an onClick perhaps, like setBackgroundColor
const onButtonClick = (color) => () => {
setBackgroundColor(color);
};
const onButtonClick = (color) => () => {
setBackgroundColor(color);
};
but state is still baffling me, so I'm not sure.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server