react-native 新建、启动项目

1、在指定文件夹内创建rn项目

npx react-native init rn  // rn是项目名

react-native 新建、启动项目_第1张图片
新建成功
react-native 新建、启动项目_第2张图片

2、android studio打开项目

react-native 新建、启动项目_第3张图片

2、启动项目

启动手机模拟器
在这里插入图片描述
启动项目

yarn react-native run-android

react-native 新建、启动项目_第4张图片

3、代码

app.json

{
  "name": "rn",
  "displayName": "rn"
}

index.js

import {AppRegistry} from 'react-native';
import App from './Router';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
// appName= 'rn','rn'是init创建的项目名
// 以APP组件为根组件渲染项目

你可能感兴趣的:(react-native)