Skip to content

Instantly share code, notes, and snippets.

@ximxim
Created October 8, 2021 22:15
Show Gist options
  • Save ximxim/51445c41f735cecccfd47e7f78d53748 to your computer and use it in GitHub Desktop.
Save ximxim/51445c41f735cecccfd47e7f78d53748 to your computer and use it in GitHub Desktop.
Using why-did-you-render library with DevSettings in React Native
import {DevSettings} from 'react-native';
import React, {useEffect, useState} from 'react';
if (process.env.NODE_ENV === 'development') {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {trackAllPureComponents: false});
}
const App = () => {
const [trackAllPureComponents, setTrackAllPureComponents] = useState(false);
useEffect(() => {
if (process.env.NODE_ENV === 'development') {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender.wdyrStore.options.trackAllPureComponents =
trackAllPureComponents;
}
DevSettings.addMenuItem('Toggle whyDidYouRender', () => {
setTrackAllPureComponents(val => !val);
});
}, [trackAllPureComponents]);
return null;
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment