`function App() {
let [state, setThings] = React.useState('pm');
let thing = '';
let count = 1;
function updateThings() {
count = count + 1;
if (count % 2 === 0) {
setThings((pre) => state = 'AM');
} else {
setThings((pre) => state = 'PM');
}
console.log(count);
}
thing = <Things items={{ data: state }} />;
return (
<div id="main">
<button
type="button"
onClick={updateThings}
className="w-48 h-20 bg-green-400 rounded-2xl m-20 ring-2 ring-white"
>
click me
</button>
{thing}
</div>
`);
}
can someone explain me the code so that i can clearly understand whats happening in the underhood
i tried to display the element as AM if num is odd ele display the number PM also prints the click count
the output i get is 2 2 3(clicked three times) where i expect 2 2 2your text
New contributor
Mr. Mysterious is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.