0

I would like to change my state in the same function from true to false and after some code ran change it back to true but when I console.log() the state it shows me that the state never changed. What am I missing here?

import { useState } from "react"

const Test = () => {
  const [someState, setSomeState] = useState(true)

  const testState = () => {
    setSomeState(false)
    console.log(someState)
    console.log("do something")
    setSomeState(true)
    console.log(someState)
  }

  return <button onClick={testState}>test</button>
}

export default Test
nicoxify
  • 13
  • 3

0 Answers0