Created
October 8, 2021 22:15
-
-
Save ximxim/51445c41f735cecccfd47e7f78d53748 to your computer and use it in GitHub Desktop.
Using why-did-you-render library with DevSettings in React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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