React and React Native archetypal model - reactjs

What is a good approach for making a React web and a React Native app that share their APIs for consuming the same database?
The system will have some CRUD screens for managing products and their images as well diferent events that the user will save.
I will follow the component / container pattern with Redux to be able to reuse code.
I am working in Windows SO.
I was thinking in:
NodeJs (APIs) and Heroku server
MongoDB
React (web app)
React Native (mobile app)
Are there some common archetypal model when using React and React Native consuming the same apis and DB?

I know I'm going to get flamed for this one....Even though it's not persistant to what you asked. I started a new project where we are using Firebase as our cloud backend and it works seamlessly between the web, ios, and android versions (building in react native).
But in regards to your question, react and react-native work well together, You can setup your redux actions (in react-native) almost identical to your react web app. The only differences between how you want to query your backend and handle auth (native uses asyncStorage vs localstorage/cookies). React native has a built in Fetch vs any other React package like Axios or SuperAgent.

Related

How to use existing amplify backend in both react and react native

I have setup a simple Amplify backend API and connected it to a React Native frontend. Now I want to connect it to a React frontend.
Could I extract all of the Amplify code into its own project to be used by both frontends? I want to avoid code duplication as much as possible. Has anyone done this before?
This is a supported feature. You can read all about it in the docs about multiple front-ends
Despite React and React Native can share the same Amplify backend, according to my research, if your application has federated sign in, you must create two different stages for them, because of the Sign-in and Sign-out redirection url, React takes http://xxxx but React Native takes myapp://.

Can I use React Redux in a mobile environment?

Can I use React Redux in a mobile environment? I am trying to distribute it over the web without using React Native
React Redux is device independent and just used for managing state for Javascript apps.
So as long as your "web app with redux" runs on a browser the type of device(tablet,phone,pc) doesn't matter.
Hope this clears your doubt.

React native web split point

I am using react native web to develop my web application.
I want to create code-split for my web application.
From my research on the web, I found that react web application has some code-split methods, which is shown in https://reactjs.org/docs/code-splitting.html
Does react native web supports these code-split techniques: import(), react.lazy, and other techniques shown in the code-splitting.html?
Don't know whether it is currently supported.

React native advantage? how to create both web and app?

how to create web and android application using react. can I use both reactJs and react native. If I create web app by using reactJs, how to convert web into android application (reactjs into react native).
Thanks in advance...
I personally in my projects have not seen a way of doing this automatically. There are some things that you might wish to look at however.
https://github.com/necolas/react-native-web - Seems to allow you to use the same components from react native directly in a react project. So the idea being you write your react native project and then import this package for the web build and voila.
I have ended up manually managing the proccess. If you layout your application keeping your application logic completely seperate from any display component logic the process really isn't that painful. Not sure if there is a better guide but this might give you an idea http://jkaufman.io/react-web-native-codesharing/
You could also use something like webpack to automate this process of swapping components / packages out for native / web.

Porting a full blown react web app to react native

I have a full blown mobile web app using the following:
React
Redux
Redux-React
React Router
Firebase
I eventually want to convert this mobile web app to a mobile app and I am looking into using React Native. There is a lot of literature on how to build React Native apps from scratch or to convert a native app in Objective-C to react native but I am struggling a bit to find some prior-art of how to approach taking a mobile web app towards native.
More specifically, what are the things that wont work out of the box? I am looking at React-Router.
Some thoughts around how to start transitioning, what to touch and what to not worry would be very helpful.
UPDATE:
Imagine the following app structure. Its already a lot of code. So, I am wondering if there are approaches to do this incrementally?
Many folks are porting their React applications to React Native incrementally by using Web View as an initial 'foot in the door', and then using React Native views on a flow-by-flow basis. With the recent availability of react-native-webview-bridge ( https://github.com/alinz/react-native-webview-bridge ), two-way communication between those web views and the react native components is now very easy.
There can be performance issues when using Web Views on iOS versus the regular Safari app, so that may force certain UI flows to be converted to React Native before you can ship.
I'd highly recommend translating any Selenium tests to Appium to keep your automated test coverage up. React Native is still a bit volatile, and being able to upgrade quickly and safely will be highly dependent on having an automated test suite.
Be sure to have your API (is you have one), your reducer and your action outside of your web folder, because you'll be able to use them in your mobile app.Most of your app structure will be the same, except for the react-router. Like Jan Fanz Palngipang, you could use react-native-router-flux (which is the one i'm using)
I would recommend you to check starter kit like nativebase, rReact Starter Pro to see how their drawer is working.(see how they change container)

Resources