PropTypes React Native is not an object

Eliott Robert picture Eliott Robert · Oct 17, 2017 · Viewed 13.6k times · Source

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 ;)

Answer

bennygenel picture bennygenel · Oct 17, 2017

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.