Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot read property 'func' of undefined in reactjs

I'm Getting the error in browser-console

 Uncaught TypeError: Cannot read property 'func' of undefined

on following line(in bundled js file)

ChannelForm.propTypes = {
  addChannel: _react2['default'].PropTypes.func.isRequired 
};

my code looks like this where i'm getting this error

ChannelForm.propTypes={
      addChannel: React.PropTypes.func.isRequired
}

Everything seems to be fine. I can't figure out what's wrong here.

like image 708
Rohit Kumar Avatar asked Dec 03 '17 20:12

Rohit Kumar


2 Answers

As says in the react documentation

React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead.

so you need to import it first like :

import PropTypes from 'prop-types';

and then use it where ever you will require propTypes like this (You can modify it accordingly)

propTypes = {
  name: PropTypes.string
};

You can read more about it here

like image 81
Aaqib Avatar answered Sep 28 '22 09:09

Aaqib


React.PropTypes no longer works. According to react docs,

React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead.

So you have to import PropTypes from the prop-types package rather, and then instead of writing React.PropTypes.func.isRequired try PropTypes.func.isRequired

like image 44
Siya Mzam Avatar answered Sep 28 '22 07:09

Siya Mzam