-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with React Native & Expo? #235
Comments
Same here - any solution yet? |
I don't know about expo, but this was super helpful for me (and no, I'm not the author :)) |
@zeevl Thanks for trying to help but It looks like this article basically just copies the installation and setup instructions from the main wdyr github page, though with less information. It also links to issue #58 here which doesn't have any resolution or workarounds mentioned in it. Let me know though if I missed anything specific that you were thinking might help. |
@duggster the main wdyr readme was has a lot of extra and misleading information that isn't applicable to get it working in RN. I got it working quickly by following the instructions in the linked post, but ymmv. Sounds like what you're running into may be specific to expo? |
If it's working for others on plain RN than chances are it is something with Expo involved (I've only ever used Expo, so I haven't tested other RN approaches). I also saw another issue #231 which is still open and I'm wondering if it has something to do with React 17.0.1 since the latest Expo also uses 17.0.1? |
This issue has to do with CRA5 and not React 17.0.1. I can't help with this one since I don't know anything about Expo. |
Had the same problem, WDYR stopped working in Expo 44. All I had to do is to add another preset to my babel.config.js, like this:
Edit: also make sure you have |
Hi @palicko I tried this and got the following error trying to run my expo app: How do I get this to work with expo? |
@duggster it seems you don't have |
Thanks, got it installed and tried running it again but to no avail. I'm still only getting the normal log outputs same as my original post, nothing from wdyr. Anything else you can think of I might be missing? Are you able to post any relevant files that might have some difference to what I have in them? Here is my updated wdyr.js and babel.config.js files (the other files in my project are still the same as my first post). I also tried removing the check for wdyr.js
babel.config.js
package.json
|
@duggster yes, forgot to add |
Thanks @palicko , I added that however I'm still not getting any wdyr log output. I confirmed my expo project is running in Development mode. babel.config.js
logs:
I'm expecting for wdyr to log that Subcomponent is re-rendering unnecessarily due to its style prop. |
@duggster I did the exact steps you described and created new project with same files as you have. Everything is working fine and I get this in my console:
Maybe try to clear Expo cache? |
@palicko thanks for confirming it works with expo at least, must be something unique to me going on here. Still not working for me even after clearing expo cache, and I tried deleting node_modules too. Next I will try starting from scratch again with another new project and will report back if it works. |
These solutions also are not working for me on Expo 46 :/ |
Works for me on Expo 46 |
@palicko actually got it working by clearing the cache as well. Expo SDK Version 46
"main": "node_modules/expo/AppEntry.js", babel.config.js module.exports = function (api) {
api.cache(true);
return {
presets: [
"babel-preset-expo",
[
'@babel/preset-react',
{
importSource: '@welldone-software/why-did-you-render',
runtime: 'automatic',
development: true,
},
],
],
plugins: ["react-native-reanimated/plugin"],
};
}; wdyr.js import React from 'react';
if(__DEV__) {
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
trackAllPureComponents: true,
});
console.log('whyDidYouRender enabled');
} App.tsx import './wdyr.js'
import { StatusBar } from 'expo-status-bar';
import { View } from 'react-native';
import useCachedResources from './hooks/useCachedResources';
import Navigation from './navigation';
export default function App() {
const isLoadingComplete = useCachedResources();
if (!isLoadingComplete) {
return null;
} else {
return (
<View style={{ flex: 1 }}>
<Navigation />
<StatusBar />
</View>
);
}
} Run expo with clearing the cache beforehand:
|
@mrzmyr with what Expo SDK version? I've spent hours trying to make this work. It doesn't work. I've created an issue on the Expo issue tracker: expo/expo#19709 |
@slapbox Version is SDK 46 |
Utterly baffling. I tried three separate projects, dozens of configs, and not one of them worked. @mrzmyr can you share the Edit: @#$%ing StrictMode. Turn it off. |
"main": "node_modules/expo/AppEntry.js", |
Hey guys, it stopped working all of sudden and just can't make it work anymore. Anyone can give a guidance to resolve this? I am on |
Just to let everyone aware, it works on SDK 47 too |
Cant get WDYR to work/log anything in Expo 48. Followed all the steps above. export const Screen = () => {
const [toggle, settoggle] = useState(false);
return (
<Page>
<DefaultButtonSelectableTextFullWidth
onPress={() => settoggle(!toggle)}
selectState={toggle ? 'selected' : 'unselected'}
title="toggle"
/>
<TestWDYR style={{ height: 50 }} />
<__________v48 />
</Page>
);
};
const TestWDYR = ({ style }: { style: ViewStyle }) => {
console.log('renderrred');
return <View style={style} />;
};
TestWDYR.whyDidYouRender = true;
|
@henkaumio if you copy and pasted from above solutions, be sure to set |
Maybe try |
i just changes wdyr.js as this and got it working in expo 49: but it was showing me only one component rerendering. I fixed it, but the component that is all the time console.logging was not shown in wdyr |
Hey all! I've been playing around with the lib and try to figure out why I was unable to get it working as well. I've ended up finding a solution that works for me and that will hopefully fix it for you all as well! In my case I use:
What I noticed by digging in the babel-preset-expo code is that they already use the @babel/preset-react preset there, and you can pass params to it. Here's what my babel.config.js file looks like:
Notice how here I pass the importSource as jsxImportSource to babel-preset-expo directly. With that done, I started expo (expo start -c) and I can now see all the logs that I need! Hope this helps anyone who comes across the issue again! |
What if we already have a jsxImportSource? For example nativewind? |
@markwitt1 I'm no expert, but I would think you'd simply be out of luck in such a case unless nativewind provides a way to handle this. |
@markwitt1 You can pass an array |
I 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
wdyr.js
package.json
I don't know much (anything) about babel so just tried this for my bable.config.js but there was no change:
All I get is this in the logs:
The text was updated successfully, but these errors were encountered: