How to architect a Web and Mobile React Native app
Should I go with react-native-web or standard react?
My 50 cents from leading a cross platform 0.5m active users project:
-
Use RN and React separately as separate projects/packages. The products will diverge over time. So will codebases. Don’t lock yourself in from the start
-
Share utils, api requests and redux where it makes sense. Be deliberate and plan accordingly. Finding the right balance between shared and split will take time, in particular early on in product lifecycle where your product is evolving rapidly
-
Set up web and native in a monorepo with the shared package to avoid versioning issues. Use yarn workspaces and make sure you hoist all dependencies
-
Ensure your tests (and types) for shared code are solid and follow good test and CI practices from the start
Is react-native-web the way to go in this case?
Definitely recommended. If the app doesn't use any or many third party modules it is very easy to add web support.
Problems start occuring when you use a lot of native features in your app that web browsers can't use or so you have to hide them or get creative with web alternatives. Or when your third party libraries don't support web which more and more do these days.
Probably not an issue with a simple app.
More on reddit.comIs React Native the right choice?
Why Use React Native for Web?
Which Companies Use React Native for Web?
Can I Employ React Native for Web for Progressive Web Applications?
Videos
Hi - I have a small project that will be accessible via Web, iOS and Android. React Native seems like the perfect fit. I started playing around with it today trying to create a singular code base (generated using React Native expo) that i can build to Web/iOS/Android. After some minor POC work i have the following concerns:
My Web app will have different layouts than the mobile apps; Im not clear on how i would apply "responsive" styling to a React Native app, or if that even makes sense (since the idea is to use native controls).
My web app and mobile apps would have slightly different navigation. Mobile would be more stack-oriented w/ the native ability to "go back", but the web would be alot more persisted top nav driven.
I immediately ran into compatibility issues when trying to add google maps to the Web view of the app. Ive spent the past 45 mins trying to get react-native-web-maps working, its seems like a PITA.
My gut wants me to have a single app, since a ton of the app is just CRUD interfaces for carious models, and some dashboards; so most of the underlying elements (forms, and submissions) will all be the same.
Or should i try to extract the API interface logic into another module, and write a React Native (for mobile) and a "regular" React app for web? TBH, i think alot of the logic will be tied up in the UI management, so i dont know that pulling the business logic out will buy me that much re-usability (its mostly just HTTP calls).
WDYT?