📜  在 setState 或状态更新后立即使用状态值更改 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:51.232000             🧑  作者: Mango

代码示例1
setMovies(result);
console.log(movies) // movies here will not be updated

so do it in useEffect

useEffect(() => {
    // action on update of movies
}, [movies]);

https://www.google.com/search?q=can+i+use+state+value+in+function+immediately+after+setting+it&oq=can+i+use+state+value+in+function+immediately+after+setting+it&aqs=chrome..69i57j69i64.10511j0j7&sourceid=chrome&ie=UTF-8