Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React v16: Uncaught TypeError: Cannot read property 'object' of undefined

Tags:

reactjs

meteor

I am getting this error and don't know what's wrong, my code is simple I'm just trying to push an array. Is so basic but yet can't figure it out.

I'm using Meteor 1.5.3 with React 16

import React, { Component, PropTypes } from 'react';

export default class ListMeds extends Component {
    render(){
        return(
            <li>{this.props.meds.text}</li>
        );
    }
}
ListMeds.propTypes = {
    meds: React.PropTypes.object.isRequired,
};
like image 783
Edwin Barahona Avatar asked Dec 04 '25 18:12

Edwin Barahona


1 Answers

This error appears because of you use the 16th version of React.js. In this blog post (announce of React.js version 16) you can read:

The deprecations introduced in 15.x have been removed from the core package. React.createClass is now available as create-react-class, React.PropTypes as prop-types...

You should install prop-types module with (if you use npm):

npm install --save prop-types

or

yarn add prop-types

for yarn case. And rewrite your code this way:

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

export default class ListMeds extends Component {
    render(){
        return(
            <li>{this.props.meds.text}</li>
        );
    }
}
ListMeds.propTypes = {
    meds: PropTypes.object.isRequired,
};
like image 122
Mikhail Shabrikov Avatar answered Dec 06 '25 07:12

Mikhail Shabrikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!