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;
如您所见,状态没有改变。我能做什么来解决这个问题。我也尝试过使用 useEffect
我尝试使用 useEffect 但没有成功
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这来自 React 文档:
这个也很有趣。