React guarantee updated state variable

I'm setting a state using the setter. In the next line I have a function which relies on the "updated" value of that state. How can I guarantee that value is the updated one and not stale? Since react does some "magic" pooling for state updates / doesn't execute state updates synchronously?

const [myState, setMyState] = useState(false)

setMyState(true)
console.log(myState) // this is not guaranteed to return true
Was this page helpful?