Amanda-Zhang
追梦女一枚

react相关

2021-06-14 前端框架
Word count: 206 | Reading time: 1min

创建一个react文件

1
2
3
4
第一步,全局安装:npm i -g create-react-app
第二步,切换到想创项目的目录,使用命令:create-react-app hello-react
第三步,进入项目文件夹:cd hello-react
第四步,启动项目:npm start

下载一个图标库react-ionicons

1
2
项目文件下 安装:npm install react-ionicons@2.1.6 --save
在要引用图标的对应文件下引入: import Ionicon from "react-ionicons"

使用PropTypes检查属性类型

1
2
3
4
5
6
7
8
在要引用的对应文件下引入:import PropTypes from 'prop-types'; 
在已引入的文件下添加:
PriceList(文件名).propTypes = {
items: PropTypes.array.isRequired, //判断变量是否是数组形式
onModifyItem:PropTypes.func.isRequired, //判断变量是否是方法
onDeleteItem:PropTypes.func.isRequired, //判断变量是否是方法

}

类型检查可以帮助我们更好的发现

Author: Amanda-Zhang

Link: http://chunchunya.github.io/2021/06/14/react%E7%9B%B8%E5%85%B3/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
虚拟DOM和Diff算法
NextPost >
promise相关概念
CATALOG
  1. 1. 创建一个react文件
  2. 2. 下载一个图标库react-ionicons
  3. 3. 使用PropTypes检查属性类型