React-Native学习(一)环境搭建以及HelloWorld

1.https://reactnative.cn/docs/0.40/getting-started.html#content,按照这个环境来搭建RN所需要的环境

2.环境搭建好之后在cmd命令行执行react-native init AwesomeProject来创建项目,命令行执行完成后此时会在C:\Users\admin文件下看到你的项目文件夹

3.cd AwesomeProject,cd到项目的根目录

4.react-native run-android来运行项目(用USB连接好真机或者在电脑上开启模拟器)

image.png

5.The development server returned response error code: 500 in react-native,报这个错的原因我在网上找到了答案
![RX11]86DB{`WUNQC7KF7AX.png
发布的0.56.0版本在windows下有bug不能正常运行请init 0.55.4的版本,react-native init MyApp --version 0.55.4,创建这个版本就可以运行了

6.在App.js文件里修改代码具体如下

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component {
  render() {
    return (
      
        Hello World!
      
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

7.再次运行


hh.png

你可能感兴趣的:(React-Native学习(一)环境搭建以及HelloWorld)