why-did-you-render when investigating re-rendering issues in your Vega apps.
Setup why-did-you-render
Step 1: Install why-did-you-render in your app project
why-did-you-render, you’re adding a crucial debugging tool to your project that helps identify unnecessary re-renders in React components, allowing you to optimize your app’s performance.
After you run the command, you should see the why-did-you-render package added to your package.json file under the devDependencies section. The package files are added to the node_modules folder in your project directory.
Step 2: Add why-did-you-render plugin in app’s babel.config.js
Add the following configuration to your app’s babel.config.js:
why-did-you-render package.
Step 3: Create a wdyr.tsx file
why-did-you-render, allowing you to initialize the library with specific settings and control its behavior across your entire app.
The wdyr.tsx file is the entry file that configures why-did-you-render tracking behavior.
The trackAllPureComponents config enables tracking Pure React Components only.
To track additional components in your app code, set whyDidYouRender on the component to true.
Example:
Step 4: Import wdtr.tsx in your app’s index.js
why-did-you-render can properly set up its hooks to track component renders across your entire app.
Step 5: Run your app in Debug mode and inspect the why-did-you-render logs
- Run your app in Debug mode. For instructions, see Set Up and Use Vega Studio.
- Perform actions in your app, such as scrolling.
-
Inspect the
why-did-you-renderlogs that appear in the app logs. To view app logs, see View logs. - Analyze the rendering reasons for components that are re-rendering.
- Fix the underlying root causes to eliminate unnecessary re-renders.
why-did-you-render log output
Grid component is re-rendering because of an update occurring within a useEffect hook.
To resolve the re-render for Grid component, remove the unnecessary state update in the useEffect hook.
Related topics
- ▶️ Improve App Performance on Vega
- 💬 Community: Using React DevTools to profile component rendering
- 💬 Community: How to solve common performance issues for Vega apps

