Scaffolding a React Native and React web project - reactjs

I'm at the starting phase of a project that is going to use React Native and React to spit out a build for iOS, Android and web that has a consistent feel. My question is: what's the best way to do this? Should I build the app in React Native and then work on porting a web build? It seems like ReactXP kind of does this, but also includes Windows stuff that we just don't need. Or is it just easier to completely separate the native from the web.
Thank you in advance for the advice!

Related

Can you use Next.js with a React Native App?

I have recently been learning Next.js for React and I like the routing system a lot more than react navigation. Now I am about to start a react native frontend and I was wondering if you can utilise Next.js's routing system in react native as well as it's other benefits. I know that you can use it with expo but I am a little confused as to how it all works and I am starting to wonder if the Next only works on the web side of things..
Does anyone have any experience with this? Any information would be much appreciated.
Thanks!
Unfortunately you can't do such thing, due to the fact that the views of react native are Equivalent to native views in Java or Objective C. When you get build version of react native , you are receiving Java or Objective C native views thank to react native's RN bridge. Meanwhile, when you get build version of your Next.js project, you are going to receive HTML, CSS, JS and these codes are not familiar to native platforms.
However, you can use your Next.js backend as your endpoints and fetch data in react native via calling this endpoints.
UPDATE Oct_2022:
there seem to be a new tool created for this purpose , called solito. I haven't used it personally but it might meet your needs.
UPDATE Jan_2023:
It looks like there are more Tools being created for Both web and native platforms , check react-native-web
You can check out Tauri. With that you can create from Next.js, React, Svelte etc. cross-platform native Apps. Currently, Windows, Mac and Linux are supported stable. Android & iOS is currently in Alpha
The magic behind Tauri is, that they provide around your Frontend library/framework a Rust layer with that you can interact with platform native APIs. They call it Commands.
You can find the guide for Next.js here.
Also, if it's not exactly answering the question - "Is it possible to use Next.js in React native?" - I hope that it's helping everyone who is searching for a solution to use Next.js as Cross-Platform Frontend Framework
I read a thread on ycombinator on this where Solito was mentioned and tried it out. In the comments I found this, which suited my needs best :
https://github.com/mlynch/nextjs-tailwind-ionic-capacitor-starter
Solito looks nice but the all in one repo was using Expo, which I did not like because it installs an extra app. I would check it out for yourself and look at the repo above too, which is using Capacitor and is aimed at having one codebase for the two apps.
Both examples worked well. For Tauri I could not find the mobile support so I didn't try it. I would be interested to read more about people's experience with running a minimum stack for cross platform development.
Note : Solito uses React Native, the repo uses Capacitor instead, which may also suite your needs because it works on both iOS and Android.
There's a lot of support now for this tech stack. Besides solito, which is already mentioned, there is also https://tamagui.dev/ which tries to solve all the issues with react-native-web and Next.js along with Solito.
While they currently recommend a monorepo (which adds a lot of complexity in my opinion), I'm playing around with a vanilla React Native + Next.js here: https://github.com/criszz77/luna
This command should get you started to play around:
npx react-native init MyAppName --template #criszz77/luna

OpenTripPlanner on React Native

I am writing my bachelor's thesis on cross-platform applications for transport management systems.
The idea is to create a React Native application with OpenTripPlanner. I have found this - https://github.com/opentripplanner/otp-react-redux and am wondering if it would be possible to open the example application through React Native on iOS and Android, possibly even web. I have opened it through WEB right now with the steps described and everything works perfectly.
Because I am very new at this, could any of you maybe help me with this? What would I need to do to open / develop the example application with React Native.
Thank you in advance. :)
Its React project, its not possible to open this project in React Native.
The suggestion is to create the react native project and then implement the code by referring the code from example library.

How do I approach multiplatform app with React

I'm just learning development and recently, I finished a MERN stack course.
Now I'm wanting to build my second Commercial App for the company where I am working.
At first, I was only considering responsive web platform but now, I can't deny the necessity of functionality on ios and Android.
Thus, I did my own research on which framework or method I will have to use to minimize my production time rather than using react web and react native separately.
It seems like Expo Web and React Native Web will be the closest solution I can think of.
I'm not sure if I'm trying to take things too easy, but if someone can enlighten me with suggestions on how to approach this dillema, that will be greatly appreciated.
In Short.
What is better? Expo Web or Native Web and best way to learn..
When using Expo, you're building the same app for iOS, Android, and Web at the same time.
Building an app with Expo CLI will provide a 100% code base across the 3 platforms. Because the Expo SDK covers most, if not, all the tools you need to build a simple application without touching native code.
Expo also offers you the possibility to eject from it, if by any chance you need to change native code.
I would suggest that you start with Expo CLI, because of how rich its SDK is and how easy it is to get started with it. And if later in time you wanna modify native code, you can eject from it.

Exporting React Native app for web (HTML/JavaScript)?

I’ve built a small app with React Native and it looks awesome, but I was wondering - can I just export it for web (HTML/JavaScript) instead making a separate code in ReactJS for it? And if it’s possible, what are the pros and cons? BTW I used a free UI kit for the developing. Thanks!
You have two options:
Use react-native-web and share 90% the same source code, between native and webapp.
Good for non-complex projects;
If your app have native/complex navigation, then it will have issues, because this can't work on web.
Use web react and share some components.
Recommended for complex projects;
If you have a complex native app, share the components can be the best option;
bit.dev can be useful to achieve this solution.
More info:
https://blog.bitsrc.io/6-ways-to-share-and-reuse-react-components-6d80e2fd16cd
You can use Expo to build for any platform: IOS, Android, Web
For the web, you can use expo build:web
It creates a production ready static bundle in the web-build/ directory
Here is the full document for the web

Cordova or ReactNative. Which should i prefer for this specific project?

I am working on a project that needs to be cross platform for web and mobile. Currently the website is being developed using ReactJS and cordova is being used to make it available on mobile.
But I was wondering if it would maybe be a better choice to use ReactNative for the mobile version because cordova might be more of a hassle than ReactNative is. I dont know if this is true tho.
I know this is kind of an open question that tends to be opinionated but i'd still like to hear some thoughts on this from you guys because its bugging me and I dont have the knowledge and experience of working on both these platforms (cordova and reactnative) to have an educated opinion.
React Native is an abstraction to write native UIs for Android and iOS. Your JS code runs in a JS runtime on the OS, but the UI is rendered as native components. This makes it very different than Cordova.
With React Native, you can use the standard platform components such as UITabBar on iOS and Drawer on Android. This gives your app a consistent look and feel with the rest of the platform ecosystem, and keeps the quality bar high. These components are easily incorporated into your app using their React component counterparts, such as TabBarIOS and DrawerLayoutAndroid.
Also you can find differences here:
https://www.toptal.com/mobile/comparing-react-native-to-cordova
Phone gap vs React Native
http://noeticforce.com/mobile-app-development-cordova-vs-react-native-vs-xamarin

Resources