Krishna Karki Krishna Karki - 4 months ago 17
React JSX Question

Do react native uses same code for ios and android or both platform code should be written separately?

Hi i have very good experience in working on Cordova with Ionic Framework and some other frameworks. Personally i m not happy with Ionic performance so i m planning to switch to React Native from Ionic.

I just want to know few things before switching. On Cordova project when you write an app for android same code will be used for ios and windows. So it saves lots of code writing. You just have to add the platform with one line command. But i m not sure about React.

Do same thing happens in React Native? Android and Ios uses same code with different platform or we have to write all code for another platform or some percent of the code are shared?

Also Ionic framework comes with lots of components and pre built UIs. Do react native also offers UIs and components?

Should i learn React js first to start React Native or i can learn React Native and React Js together?

Can we use React Native code for web platform?

Answer

So, let us start with the React Native slogan "Learn once, write anywhere". This pretty much answers your first question. You have to write code both for your android app and your iOS app. This is because android and iOS have different native components. You can reuse some of your code like logic, how to distribute data (for the most) etc, but you will have to tune this to work with the native components of both android and iOS.

Second question. React Native enables you to utilize a lot of already well known components. Also the community enables different other components if it is not in what Facebook already have released. If you for some reason want something no one have made a port for, you will need to do some native programming to enable such a component.

Third question. The best is of course to learn React first, but you can easily learn React as you code React Native. React Native Playground is a nice place to play around with React Native. Again, this depends on how you like to learn new frameworks and languages.

Fourth question. No you can not use React Native code as a web app. This is because your React Native app will be using native components. In iOS you use <View /> which is the same as <div /> (Pretty much). This does not mean you are not empty handed if you want to create a web app afterwards. You can use parts of your layout and re-write them to work on the web. Like translating view to div, image to img etc.

gl