I'm trying to implement the following yes/no buttons:
import React, { useState } from "react";
const YesNoComponentFunctional = () => {
const [button, setButton] = useState("");
const onYesPress = () => {
setButton("Yes");
console.log({ button });
};
const onNoPress = () => {
setButton("No");
console.log({ button });
};
return (
<div>
<button onClick={() => onYesPress()}>Yes</button>
<button onClick={() => onNoPress()}>No</button>
</div>
);
};
export default YesNoComponentFunctional;
Wich I got from this article here.
And I can't understand why I have to click the buttons twice to properly display the message to console. Why is that happening?