How to use with React Native & Expo?
See original GitHub issueI have used wdyr with my RN Expo app in the past, maybe a year ago, but now it is not showing anything in the logs. Any help would be greatly appreciated!
I created a new RN Expo app to use as a simplistic, reproducible example:
expo init wdyr-test
and choose option for blank project (managed workflow).
App.js
import './wdyr'; // <--- first import
import React, { useState } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default function App() {
const [count, setCount] = useState(0);
const onPress = () => {
console.log("Increment Pressed");
setCount(prev => prev + 1);
}
console.log("App RENDER");
return (
<View style={styles.container}>
<Text>{count}</Text>
<Button title="Increment" onPress={onPress} />
<Subcomponent style={{ height: 100, width: 100, borderRadius: 50, backgroundColor: "blue" }} />
</View>
);
}
const Subcomponent = React.memo(({ style }) => {
console.log("Subcomponent RENDER");
return (
<View style={style} />
)
});
Subcomponent.whyDidYouRender = true;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
margin: 50
},
});
wdyr.js
import React from 'react';
if (__DEV__) {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
trackAllPureComponents: true,
});
}
package.json
{
"name": "wdyr-test",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-web": "0.17.1"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@welldone-software/why-did-you-render": "^6.2.3"
},
"private": true
}
I don’t know much (anything) about babel so just tried this for my bable.config.js but there was no change:
module.exports = function (api) {
api.cache(true);
const isDev = process.env.BABEL_ENV === "development";
return {
presets: [
['babel-preset-expo',
{
jsxRuntime: 'automatic',
jsxImportSource: isDev ? '@welldone-software/why-did-you-render' : 'react'
}
]
],
};
};
All I get is this in the logs:
App RENDER
Subcomponent RENDER
Increment Pressed
App RENDER
Subcomponent RENDER
Increment Pressed
App RENDER
Subcomponent RENDER
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:22
Top Results From Across the Web
How to use Expo with React Native - Robin Wieruch
Expo is a powerful environment for React Native which helps you from creation to distribution of your React Native apps. Without the need...
Read more >Already used React Native - Expo Documentation
Expo extends the React Native platform by offering additional, battle-tested modules that are maintained by the team. This means you're spending less time ......
Read more >Create React Native app using Expo CLI or ... - Codemagic Blog
Create React Native app using Expo CLI ... This will start a development server for you. To run the app, install the Expo...
Read more >Building Your First React Native Application with Expo
It is recommended that developers who are new to mobile application development, use the Expo CLI to develop apps faster, easier, and more ......
Read more >Create a React Native app with Expo tutorial
How to create an Expo app tutorial · Install the Expo client · Create a new Expo project · Set up a git...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@palicko actually got it working by clearing the cache as well.
Expo SDK Version 46
package.json
babel.config.js
wdyr.js
App.tsx
Run expo with clearing the cache beforehand:
Works for me on Expo 46
npx cross-env NODE_ENV=development expo start -c