React Native version upgrade and downgrade (1) Introduction
Now that React Native For Android has just been open source, it is not long ago that the overall functions are still not perfect and there are still a lot of bugs in development, so that there is no official version yet. The project staff is stepping up development and maintenance to fix the bug, so the version update speed of the React Native project is still relatively fast. Under such circumstances, we must pay close attention to the project's official website in a timely manner, and update React Native to the new version, so that we can use more APIs, view Views, and developer tools and other useful things.
We all know that a React Native project is composed of three parts: Android project, iOS project and JavaScript project, and all three are associated and packaged in the npm package, so updating the project version is relatively cumbersome. Let me explain the upgrade steps of the React Native project. (2) Upgrade React Native version View local React Native version
First, we need to check the local version of React Native. Enter the following command on the command line:
react-native --version
If it is created directly from the command line npm install -g react-native-cli according to the previous article, then the following situation should appear:
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/fc420bdd-a612-4de3-a06f-e67e07443eec)
It is found that the version number is 0.2.0, which is actually the local cli version. At this time, you need to enter the React Native main directory that was created before executing react-native –version.
At this time, you can view the React Native version and cli version.
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/16a4c714-6791-4b5d-91e8-5fffa1f9ae84)
React Native version upgrade and downgrade You can also enter npm info react-native on the command line to view and return a JSON object, as shown below:
The latest version is currently 0.27.0-rc2, which is a preview version.
Let's take the AwesomeProject project created earlier as a test. Open the package.json file in the project, find the dependencies field, and modify the version of react-native to be higher than the current project version, as shown in the figure:
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/965bf5f3-d6ee-44ad-82ee-adb751b77bac)
Next, switch to the main directory of the project and execute the following code. This installation process will take some time:
npm install
If the following interface appears, it means that the upgraded version is successful.
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/6a023bbd-335c-4535-a381-764264111fdc)
Next, run the react-native --version command in the project directory to view the current version:
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/274594b9-986f-4868-b55f-ce39b919bc11)
The appeal method is to manually modify the configuration file to update. You can see from the official documentation that it is now supported to run the npm install --save command in the project to install the new version of react-native. For example, if you need to update to version 0.27, you can execute the following command :
npm install --save react-native@0.18
(3) Update project templates
The version of the project template will also change with different versions, so after updating the React Native version, the project template should also be updated in time.
Through the following command:
react-native upgrade
Run screenshot as follows:
![](http://aliyunzixunbucket.oss-cn-beijing.aliyuncs.com/csdn/87a2c48b-d786-448f-aa30-da6b1e985d6f)
[Do not heed] In the red box above, the file modification check will be carried out, choose to overwrite or keep the original file, depending on your actual situation, all choose not to overwrite here.
There are three principles: if it is a newly added file, it will be created directly. If the update file is the same as the original file, skip it directly. If the update file is different from the current project file, there is a conflict, and the developer will be asked to choose whether to overwrite or keep the original file. , Depends on the actual situation.
After the update is complete, run it to see if there are any problems. (4) Downgrade of React Native version
The React Native version has just been upgraded. Now if it is the latest version, but the latest version is not particularly stable, and you always encounter unexpected bugs during development, you can consider reducing to a more stable version. The same is the above two methods. The first one is to modify the package.json file; the second one is to directly execute npm install --save react-native @ version number.
After passing the appeal, do n’t forget to update the template.
react-native upgrade
Finally run it to see if there is a problem.
Reprinted from: http://www.lcode.org/