Open
Description
新版本的react的prop-type已经单独成包了,所以要先安装prop-types模块
npm install prop-types --save-dev
import React from 'react';
import PropTypes from 'prop-types';
class Skill extends React.Component {
//code
constructor(props) {
super(props);
// 设置 initial state
this.state = {
text: props.initialValue || 'Hello Wscats'
};
}
}
注意这里以前是React.PropTypes
,现在为PropTypes
Skill.propTypes = {
//定义传入props中的属性各种类型
initialValue: PropTypes.string.isRequired//PropTypes.string
};
Skill.defaultProps = {
//组件默认的props对象
initialValue: 'Hello Oaoafly'
};
Metadata
Metadata
Assignees
Labels
No labels