I created a function like this.
export function Counter() {
const [count, setCount] = useState(0);
const countUp = () => {
setCount(count + 1);
}
const countUpAndShow = () => {
setCount(count + 1);
alert(count);
}
// I won't call after countUp function, call only countUpAndShow function.
useEffect(() => {
alert(count);
},[count])
return <div>
<button onClick={countUp}>count up!</button>
<button onClick={countUpAndShow}>show count!</button>
</div>
}
I want to call alert(count) after setCount().
but alert(count) not show count correctly.
then, I use useEffect like above. but I want to call alert() only countUpAndShow function.
how to solve it ?