What does "ejecting CRNA app is not reversible" really mean? - create-react-native-app

I've read some docs that says that ejecting a Create React Native App (CRNA) is irreversible. Im not sure what this means exactly.
Will I not be able to build my apps again for App Store, Play Store? Is it just a 1-time feature?
Will I lose files/ code that prevents me from ejecting a second time?
I'm trying to dig a little deeper into this. If anybody could share links to relevant blogs or forums, that would be great.

Ejecting is irreversible in the sense that if you modify the ejected project, you cannot convert it back into a CRNA project (except by creating a new CRNA project and copy/pasting all your code)
You can build for the App Store/Play store from a CRNA or an ejected project. For CRNA you would usually use exp:build and for ejected apps you could build from XCode. If you're only ejecting to get a standalone app, don't do it! Check out Expo's building standalone apps.
If you're worried about ejecting and losing you're original CRNA project, I recommend duplicating it before ejecting.
There's no reason to eject more than once. If you've ejected you can continue working on the ejected project.

Related

How can i run reactjs locally on mac other than the npx create-react-app?

I'm just a bit annoyed by having to do npx create-react-app and wait then delete most of the files and code.
I've seen some people use npm i react react-dom, is this another way as well?
can i also use react offline ?
You can add a in your html if you don't want to use create-react-app. Then just create a file with that name. Otherwise I believe other methods still give you a boilerplate.
Even if without create-react-app, can make React applications. But it's bother than with it. create-react-app just automates downloading libraries and many many configurations. So what they do is same.
Create react app creates spa and gives entire folder structure out of the box, but you don't always need to use cra command for that, you can create spa yourself with minimal packages if you know the actual working of spa, you can use react, webpack, webpack dev server, babel.

Is it best practice to escape create react app and create our own template to get React project ready for production?

I am new to React and recently joined a team and my first assignment was to set up a react project without using create-react-app because as team lead told me custom template makes easier to put react into production. Then, the question is how about create-react-app helping us with all of the setup for us and if we want to customize the CRA we can use npm run eject. So, why should we create our own template?
On the contrary, it's pretty hard to setup a React application without a template.
You can check Creating a Toolchain from Scratch at React docs which refers to this guide.
Your own template should configure package manager, bundler and compiler, it's not so trivial. Best suggestion would be extending CRA by cloning the repo or running yarn eject and continue from there.

why there is need to create a React app from scratch with Webpack and Babel if create-react-app automatically adds them?

why there is need to create a React app from scratch with Webpack and Babel if create-react-app automatically adds them? I am kind of new to this thing could someone please help me to understand this thing
Because some people might not want the setup that create-react-app provides.
There are many different ways to set up a project, you can do it from scratch, by using someone elses's template, or using a CLI tool like create-react-app.
The choice is yours, but the recommendation for beginners is to just use CRA as it is the simplest and gets everything working together nicely for you to just get building!

Remove expo from react native

I've had so many troubles with the tool, I seriously have been debugging expo morethan the app itself.
How might I remove expo completely from CRNA? I would like to use CRNA and it's debugging tools without expo
You can do it by ejecting your app running npm run eject
Then, if you have any reference to expo just remove all of them.
your app modules before being ejected looks like this below:
When you run npm run eject it will ask some questions like:
be sure to select React Native: I'd like a regular react Native project
And your folders will now look like this (no expo):
Just be careful because ejecting is a permanent process, you should make a backup of your files.
Once you eject from Expo, though, and if you're using a Windows computer, you'll only be able to develop for Android, I believe. You'll still need a Mac to work in React Native without Expo. I'm a beginner but just wanted to highlight this difficulty faced by Windows users when ejecting from Expo.

What is the quickest way to convert a React app to React Native?

This may be a naive question, but I couldn't find too much information on this topic.
I have a fully functional react-redux application and I would now like to port it to iOS and Android. I have no need to use any native features like GPS or Camera etc. In theory I just want to make a sort of webview that runs the existing React app, and then tweak it until it looks more presentable.
My first attempt was to simply use my current jsbundle file and stick it into the AppDelegate as the jsCodeLocation. That expectably caused all sorts of errors such as "window" not being defined.
I guess my question is: how do people usually manage their native and non-native codebases? Are they completely separate, or is there a way to recycle most of the code?
As others have mentioned there's no quick way to convert react to react-native.
A possible alternative if you want your react app to run on a mobile device without rewriting your codebase is to use Cordova. For fun I ported a react-web app into a mobile app using Cordova in just a few minutes. There are some drawbacks to this method, but the benefit is that you can have a working mobile app in very little time.
Below are the steps if anyone is interested in a Cordova workaround alternative:
REACT SETUP (done in command line)
>1. npx create-react-app my-app
>2. cd my-app
>3. npm start
DEPLOY TO STATIC:
>1. Update your package.json file from your my-app directory to add "homepage":"." (see below)
"name": "my-app",
"version": "0.1.0",
"private": true,
"homepage":".",
"dependencies": {
>2. Build (in command line) npm run build
CORDOVA INTEGRATION (in command line)
>1. cd ../ (change to wherever you want the project created, don't do this inside your existing react app folder)
>2. npm install -g cordova (only if you already don't have Cordova installed)
>3. cordova create MyApp
>4. cd MyApp
>5. cordova platform add ios //or android or browser
ADD A COUPLE STEPS FOR INCLUDING YOUR REACT PROJECT
>1. Open your Cordova MyApp www folder, delete all files and folders in it except for the 'js' folder
>2. Back in your react build folder update the index file to add two cordova scripts:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
>3. copy all your files from the react build folder into the Cordova www folder (replacing everything except the js folder)
BUILD REACT-CORDOVA APP (in command line, inside your Cordova project)
>1. cordova build ios //or android or browser
TEST OR DEPLOY TO STORE ETC.
>1. Use xcode to open open your react-cordova .xcodeproject, this can be found in the MyApp/Platforms/ios/
>2. Select your simulator and run. Enjoy your new mobile app!
TWEAK
There are some minor tweaks you'll need to do (like remove the tap delay...etc)
-I think this is why people think Cordova apps are slow, but it's an easy fix...
You cannot just use your whole code into the react native application. First and foremost, you have to follow the react native architecture and then develop your UI using react native components.
https://facebook.github.io/react-native/docs/getting-started.html
You'll get most of the help here.
There is another option also, you can just create a new react-native project and use webview in it and display your whole website there.
https://facebook.github.io/react-native/docs/webview.html
Some of the reusable things are styles:
var style = {
box: {height: 30, width: 30, padding: 10, ect...}
}
Logic such as state :
constructor(props){
super(props);
this.state= {text: "hi"};
}
the state can be shared between navite and dom like so
<View>
<Text>this.state.text</Text>
</View>
dom looks like this
<div>this.state.text</div>
You can even share functions but you have to be careful like it was stated above, as long as you're not directly invoking any dom or refs in your logic.
onClick(){
this.setState({text: "good bye"});
}
They're usually pretty separate, partly because your render target is different (i.e. no divs) and partly because of things like window not being available. It's possible to reuse code between web and native apps, but only if you're very careful about it.
From the react native release blog post:
It's worth noting that we're not chasing “write once, run anywhere.” Different platforms have different looks, feels, and capabilities, and as such, we should still be developing discrete apps for each platform
WebViews and React-native are two completely separate concepts. Either you want to go with the former (than you can actually use your application without much hassle), or with the latter. In that case, you could probably re-use some of the business logic, however most of the rendering would have to be rewritten.
React native is learn once, write anywhere, not learn once, write once :)
For those who searching for a way to code once with react-native and export for Web, Android, and IOS, I suggest Expo.
It suggests building for the web just with this command expo build:web. Here is the full document
And about Webview that you have mentioned, I had made projects for Web and then use Webview to make mobile application of them, but it should be fully responsive and SPA to act as a real application when navigating between pages.
My own examples are: Web: Mehrg.com Android: Home Design App And another example is vitrinom
Updating an answer for 2022: Ionic (although this tech came about in [2013])(https://en.wikipedia.org/wiki/Ionic_(mobile_app_framework))
You can use Ionic!
I am planning on using it for a few of my bootstrapped projects where I would like to prove concept first before doing a full on Native build.
Some pros of Ionic:
Support for React, Angular, Vue
fast to build and deploy to both iOS and Android
can be built using browser based technologies i.e. traditional React development
JS is all you need (I suppose HTML, CSS, etc too)
plugins for mobile device features such as camera, fingerprint, NFC, geoloc, push notifications, deep links, etc
Cons:
Debugging is hard
Error messages are vague, which makes Debugging harder
You need to go through the app on your device in order to debug device specific issues. But this would be necessary for native builds anyways.
Sometimes builds just crash!
My advice with technologies such as Ionic and Cordova (mentioned by #Paul Schorey) is tread with caution when using these tools live for real users. It is probably best to have plans to go native as soon as you are able to, have the resources, or have the users that necessitates migration.
You have to refer the react native structure to actually understand how to convert your react app to your react native app.
To start from scratch I would suggest: https://reactnative.dev/docs/getting-started

Resources