Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一直困扰我的一个问题,为什么用了函数组件之后加载页面一个方法会被执行了几次 #6

Closed
yzbgyq opened this issue Aug 14, 2019 · 2 comments

Comments

@yzbgyq
Copy link

yzbgyq commented Aug 14, 2019

207d51ec50af96a3967625a724a666c (1)

@sanyuan0704
Copy link
Owner

没事,你输出一下props,看看里面的数据有哪些变化,就知道一步步更新的原因了

@sanyuan0704
Copy link
Owner

对这个页面而言,第一次页面挂载,所有数据都是初始状态,第二次bannerList更新,重新执行,第三次recommendList更新,重新执行,第四次 enterLoading更新,再次执行。顺便提一嘴,为了减少组件切换带来的重复渲染,我在useEffect里面其实是用了redux做了数据层的缓存,不知道你注意没有,这样你切到别的路由在切回来只会渲染一次。

@yzbgyq yzbgyq closed this as completed Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants