简体   繁体   English

如何在 React 中的父组件“useEffect”之后运行 function

[英]How to run a function just after parent component "useEffect" in React

I have a react app with parent component app.js and a child component homepage.js.我有一个带有父组件 app.js 和子组件 homepage.js 的反应应用程序。

So when I refresh the page useEffect hook from homepage.js runs first and then app.js useEffect runs but I have some functionality that is dependent on app.js useEffect I want that code run automatically after page refresh and after the useEffect in app.js.因此,当我从 homepage.js 刷新页面 useEffect 钩子首先运行,然后 app.js useEffect 运行但我有一些依赖于 app.js useEffect 的功能时,我希望该代码在页面刷新后和 app 中的 useEffect 后自动运行。 js。

if you want to execute parent component code first then in parent instead of using useEffect() execute that code in useMemo()如果您想先执行父组件代码,那么在父组件中而不是使用 useEffect() 在 useMemo() 中执行该代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM