构建项目
Yarn 是 Facebook 提供的替代 npm 的工具, 可以加速 node 模块的下载 React Native 的命令行工具用于执行创建初始化更新项目运行打包服务 (packager) 等任务
npm install -g yarn react-native-cli
安装完 yarn 后同理也要设置镜像源:
- yarn config set registry https://registry.npm.taobao.org --global
- yarn config set disturl https://npm.taobao.org/dist --global
Watchman 是由 Facebook 提供的监视文件系统变更的工具安装此工具可以提高开发时的性能 (packager 可以快速捕捉文件的变化从而实现实时刷新) 译注: 此工具官方虽然是推荐安装, 但在实践中, 我们认为此工具是必须安装, 否则可能无法正常开发
brew install watchman
测试安装: 构建一个简单项目
- react-native init MyApp --version 0.44.3
- cd MyApp
react-native run-ios 运行项目
或者运行项目: 双击 ios/AwesomeProject.xcodeproj 文件然后在 Xcode 中点击 Run 按钮
在项目下新建 components 文件夹, 存放所有组件
APP.js 入口文件
传参给组件 New.js 自定义属性
<New data={data}></New>
组件可通过 this.props.data 接收参数
来源: http://www.jianshu.com/p/5e8d669e0ff1