简体   繁体   English

React Re-Render 导致闪烁:我该如何解决?

[英]React Re-Render Causes Flickering : How can i fix this?

I'm new in coding and i couldn't get how to fix the issue after i googled many times.我是编码新手,在谷歌搜索多次后我无法解决这个问题。 The issue is i have a layout component which contains 4 different components.问题是我有一个包含 4 个不同组件的布局组件。 When i call a function in a function component it affects the others and the others re-render.当我在 function 组件中调用 function 时,它会影响其他组件并且其他组件会重新渲染。 Re-render is fine tho however my images are flickering on mobile browser.重新渲染很好,但是我的图像在移动浏览器上闪烁。 I would like to remove the flickering of the image loading.我想消除图像加载的闪烁。 I've tried using React.memo() and useCallBack() but both of them didn't work for me.我试过使用 React.memo() 和 useCallBack() 但它们都对我不起作用。 I hope I made myself clear, thanks in advance我希望我说清楚了,提前谢谢

This is my app https://stackblitz.com/github/mithatercann/qrmenu这是我的应用程序https://stackblitz.com/github/mitthatercann/qrmenu

You are using what's its called "Prop Drilling".您正在使用所谓的“Prop Drilling”。 The better solution for your current problem is to implement some state management in your app, they are many third libraries for that, but for this instance and if your app is small you can use React Context API .对于您当前的问题,更好的解决方案是在您的应用程序中实现一些 state 管理,它们是许多第三方库,但是对于这种情况,如果您的应用程序很小,您可以使用React Context API If you're going to build big apps then I recommend implementing Redux .如果您要构建大型应用程序,那么我建议您实施Redux

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

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