I have a react js web application project. I need to develop the same project as mobile application.
Can i convert my reactjs web application project to react-native mobile application project?
If it is yes, How can i do it?
CodePudding user response:
no you can't convert. you need rebuild as you can use logic and most of the code from you react js but a few things you need to update like routing and Jsx etc
CodePudding user response:
There is no quick way of converting a whole React App to React Native, you need to take care of Native components, setup, and configs, for example, in a React App the Entry point is your index.js file, packed by ReactDom, in React Native(or expo) you will need to set up an AppRegistrty and probably a Metro bundler. However, if it's a component you want to transform into a ReactNative component, it's doable, considering these few similarities:
- A
<div />
can be substituted by aView />
imported fromreact-native
- A
<button />
by<TouchableOpacity />
- Put all your texts into
<Text />
All imported fromreact-native
About styling
None of those React Native components has a className: string
props, instead use style: object
props
About navigation
Too many differences here, you have to set up a custom navigation logic helped by the react native navigation library
Briefly, you cannot directly translate a react codebase into a react native, however, a single component exporting a JSX element(like a button, a card, ...) can be using those technics I shared Additionally, This thread can be a big plus