Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PropTypes React Native is not an object

I have a problem with PropTypes in react native my code :

import React, { Component, PropTypes } from 'react';
import { Text } from 'react-native';

export default class Star extends Component {
    render() {
        return ( <Text> Hello </Text> );
    }
}

Star.propTypes = {
    fullStar: PropTypes.string.isRequired,
    halfStar: PropTypes.string.isRequired,
    emptyStar: PropTypes.string.isRequired,
    half: PropTypes.bool,
    count: PropTypes.number,
    size: PropTypes.number,
}

Star.defaultProps = {
    fullStar: "",
    halfStar: "",
    emtyStar: "",
    half: 'true',
    count: 5,
    size: 30,
}

My error is undefined is not an object (evaluating '_react2.PropTypes.string')

Thanks for read ;)

like image 621
Eliott Robert Avatar asked Oct 17 '17 13:10

Eliott Robert


2 Answers

PropTypes moved into separate package. Use prop-types package.

More info here.

Note:

React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead. We provide a codemod script to automate the conversion.

like image 101
bennygenel Avatar answered Sep 22 '22 15:09

bennygenel


Yes, PropTypes has been deprecated from version 15.x you need to install the package:

npm install prop-types

and then import it.

import PropTypes from 'prop-types';
like image 28
Luis Nolazco Avatar answered Sep 26 '22 15:09

Luis Nolazco