Reputation: 41
I have a React App that is currently re-rendering more often than I'd like. I'm using React DevTools Profiler to record my session and I have the option checked to record why the components re-render.
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. 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
Upvotes: 4
Views: 3601
Reputation: 512
The component is most likely being re-rendered due to a change in context, and the React DevTools isn't reporting this accurately.
See https://github.com/facebook/react/pull/17068 for some more detail on the DevTool reporting in this situation.
Upvotes: 3