const [button, setButton] = React.useState("off")
React.useEffect(()=>{
setButton("on");
console.log(button)
},[])
const onClickHandler = ()=>{
setButton("off");
}
Lets take this code as an example, every time i reload the page, I expect the button to console log "on" since i did setButton("on")
but it console logs "off" but when I click on that button it should setButton("off")
but now it prints out 'on'. so its like its one step behind. why is it happening. and when should i use useEffect. Sorry about my english.