react-native PropTypes

来源:互联网 发布:金融机构利用电话网络 编辑:程序博客网 时间:2024/05/17 06:56
  在学习react-native过程中,设置自定义组件  PropTypes遇到了个坑
import React, { Component , PropTypes} from 'react';import {  Platform,  StyleSheet,  Text,  View} from 'react-native';export default class PropsTest extends Component<{}> {  static defaultProps={    name:'小红',    age:10  }  static propTypes={    name:PropTypes.string,    age:PropTypes.number,    sex:PropTypes.string.isRequired  }  render() {    return <View>      <Text style={{fontSize:20,backgroundColor:'red'}}>姓名:{this.props.name}</Text>      <Text style={{fontSize:20,backgroundColor:'red'}}>年龄:{this.props.age}</Text>      <Text style={{fontSize:20,backgroundColor:'red'}}>年龄:{this.props.sex}</Text>    </View>;  }}
一直报错,找了N多方法,最后终于解决
import PropTypes from 'prop-types';
 
原创粉丝点击