React-native: undefined is not an object evaluating ReactPropTypes.string

Created on 19 Jun 2017  路  13Comments  路  Source: facebook/react-native

react-native run-android锛宼hen
error
undefined is not an object evaluating ReactPropTypes.string

Locked

Most helpful comment

After version 15.5 you have to import PropTypes from prop-types like below:

import React from 'react';
import PropTypes from 'prop-types';

class Component extends React.Component {
render() {
return

{this.props.text}
;
}
}

Component.propTypes = {
text: PropTypes.string.isRequired,
};

All 13 comments

@damiaozi maybe you are having the same issue as https://github.com/facebook/react-native/issues/14588 ? What version of RN are you?

the same problem here. Anybody has fixed the problem?

After version 15.5 you have to import PropTypes from prop-types like below:

import React from 'react';
import PropTypes from 'prop-types';

class Component extends React.Component {
render() {
return

{this.props.text}
;
}
}

Component.propTypes = {
text: PropTypes.string.isRequired,
};

@cromasystem yes it works thanks. i have replaced React.PropTypes with PropTypes

@cromasystem do i have to do this for every component?

good quest @elvismercado

import PropTypes from 'prop-types';

worked for me !! Thanks

import PropTypes from 'prop-types';
This works for me too.

use
import React from 'react';
import PropTypes from 'prop-types';

screen shot 2018-01-22 at 4 23 15 pm

what specific module or file did you change?? going nuts.. doing this...

@Shazam14 you will have to make the change in both your modules and those modules of the libraries you have declared in your package.json. There's a lot of pull requests waiting to merge these fixes into various libraries that I've run into, but until those are merged and packaged for deployment, you will have to make the temporary fix yourself.

For instance, you will need to change:

import React, { Component , PropTypes } from 'react';
to
import React, { Component } from 'react';
import PropTypes from 'prop-types';

Was this page helpful?
0 / 5 - 0 ratings