import React, { PureComponent } from "react";
import PropTypes from "prop-types";
const s = Symbol(1);
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class Greeting extends React.Component {
static propTypes = {
name: PropTypes.string,
array: PropTypes.array,
func: PropTypes.func,
num: PropTypes.number,
obj: PropTypes.object,
string: PropTypes.string,
symbol: PropTypes.symbol,
node: PropTypes.node, // 任何可被渲染的元素(包括数字、字符串、子元素或数组)
element: PropTypes.element, //一个 React 元素
point: PropTypes.instanceOf(Point), //你也可以声明属性为某个类的实例
enum: PropTypes.oneOf(["News", "Photos"]), // 你也可以限制你的属性值是某个特定值之一
union: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.instanceOf(Point)
]), // 限制它为列举类型之一的对象
arrayOf: PropTypes.arrayOf(PropTypes.number), // 一个指定元素类型的数组
objectOf
PropTypes例子
最新推荐文章于 2022-05-30 15:52:29 发布