简体   繁体   English

在 React DevTools 中,我的组件正在重新渲染,但父组件没有,并且它的状态/道具没有改变

[英]In React DevTools my component is re-rendering but the parent is not, and it's state/props are not changing

I have a React App that is currently re-rendering more often than I'd like.我有一个 React 应用程序,它当前重新渲染的频率比我想要的要高。 I'm using React DevTools Profiler to record my session and I have the option checked to record why the components re-render.我正在使用 React DevTools Profiler 来记录我的会话,并且我选中了记录组件重新渲染的原因的选项。

For the component in question, under 'Why did this component render?'对于有问题的组件,在“为什么此组件呈现?”下it says 'The parent component rendered.'它说“呈现的父组件”。 However in the component tree of the devtools, none of the parent components are rendering.然而,在 devtools 的组件树中,没有任何父组件正在渲染。 They all say 'Did not render during this profiling session.'他们都说“在此分析会话期间未呈现”。 The component I'm troubleshooting is basically the highest level component in the actual project.我正在排查的组件基本上是实际项目中最高级别的组件。

Above it are the following components:在它上面是以下组件:

App应用程序

BrowserRouter浏览器路由器

Router路由器

Context.Provider上下文提供者

Switch转变

Context.Consumer上下文.消费者

Route路线

Context.Consumer上下文.消费者

Context.Provider上下文提供者

MyComponent我的组件

The component is most likely being re-rendered due to a change in context, and the React DevTools isn't reporting this accurately.由于上下文的变化,组件很可能被重新渲染,而 React DevTools 没有准确报告这一点。

See https://github.com/facebook/react/pull/17068 for some more detail on the DevTool reporting in this situation.有关这种情况下 DevTool 报告的更多详细信息,请参阅https://github.com/facebook/react/pull/17068

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

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