I am trying to use reactHook from an example like this;
const [newAccount, setNewAccount] = useState(true);
const toggleAccount = () => {
setNewAccount((prev) => !prev);
}
newAccount is to tell whether the user already has on account, and made an event to function to toggle the status of NewAccount.
I thought in setNewaccount ,I should put a value as param like;
setNewAccount(!newAccount);
It works, but the example puts an arrow function ((prev)=>!prev);
,and still it does work too. I am quite confused as why it works.
In my opinion, by using setNewAccount like that doesnt newAccount become a function {{prev)=>!prev}
, not the boolean value that I originally thought?