React functional component does not update state
P粉486138196
P粉486138196 2024-03-30 10:48:58
0
1
465

function Example() {
  const [state, setState] = useState(0)
  
  const someFunction= ()=>{
    ///some task that return a value
    let value = getFunction()
    setState(value)
    console.log(state) //prints 0 ???
  }

  return ( <></> );
}

export default Example;

As you can see, the status has not changed. What can I do to solve this problem. I also tried using useEffect

I tried using useEffect without success

P粉486138196
P粉486138196

reply all(1)
P粉510127741

This is from the React documentation:

This is also very interesting.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!