-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Bugs when using mobx in react native (fast-refresh) #3160
Comments
Expo sdk42 is not compatible with react 17. Try upgrading to sdk43? |
I have apps with react 16 and expo 40/41/42 and the error is the same. It's not version incompatibility, because I always start a project with "expo init" |
I am experiencing the same problem and I managed to figure out what is to blame for this babel plugin. A few days later I found out what caused it. I am using mobx 6 on a project and the documentation states what needs to be added to babel.config.js is(@babel/plugin-proposal-class-properties):
As soon as I remove the connection of this plugin, everything starts working normally. At the moment I don't understand how this affects metro and how I can still use the specified plugin. I tried to make various configurations. this comment also helped me solve the problem my info:
|
@Yrsafam Are you, by any chance, transpiling modules, that are not defined by you - like |
Hi, as far as I can see, only my code is being broadcast, but because a fix related to override for babel.config helped me.js, then I assume somewhere there is a transpilation inside the react-native config, which broke everything |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
i think i solved this problem inside react-refresh. I disabled the next update if the component name is "observerComponent". I don't know if I should do a PR as this is a mobx specific issue and maybe the react team doesn't want to include: misaeldossantos/react@f6eb19d. Maybe it's possible to add a property in the component function to disable refresh in any component that needs it: Component.disableReactRefresh = true, but I'm not sure that's a good thing |
This is still relevant on any bundler with any transpiler plugin. It is obvious that it is never going to be resolved on the React side. Is there something that we can do about it? |
No idea. Anyone investigating / championing a solution is welcome :) |
I like mobx a lot, but it has been difficult to use it in react native with fast refresh. There are several problems that have occurred, some were reported some time ago, but have not been resolved.
Intended outcome:
I am trying to use mobx with react native and have the code updated correctly when I am developing
Actual outcome:
I will list some problems I had:
When I wrap the component in a "observer", adding or removing any hook inside the react component causes the application to crash with the error: "Rendered fewer hooks than expected..." (already mentioned at Rendered fewer hooks than expected with React Fast Refresh while using observer #2668).
When I change the code inside the useLocalObservable hook, the code is not updated in the app. I have to close the app and open it again for the change to be persisted. If the component is not wrapped in an observer, changing the code causes the application to be reloaded from scratch. This is very bad.
When mobx class code is changed (built with makeObservable or makeAutoObservable), the application reloads from scratch.
I really like mobx, both for the ease of writing code and the performance benefits, but that makes me sad, I have been facing these problems for about 2 years. It makes the library seem unstable.
How to reproduce the issue:
Create an application with react native
Wrap the component for testing in mobx-react observer function
Use the useLocalObservable hook inside the react component
Change the code in useLocalObservable
Versions
"mobx": "^6.3.3",
"mobx-react": "^7.2.0",
"react": "^17.0.2",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
The text was updated successfully, but these errors were encountered: