1

I'm using react-router v3.2.0 and this is my app.js, error is showing on line router: PropTypes.object in chrome and in edge it shows error as TypeError: Unable to get property 'object' of undefined or null reference at class App extends React.Component , btw I am new to react

import React, { PropTypes } from 'react';
import { Router } from 'react-router';
import './App.css';

class App extends React.Component {
  static contextTypes = {
    router: PropTypes.object
  }

  static propTypes = {
    history: PropTypes.object.isRequired,
    routes: PropTypes.element.isRequired
  };

  get content() {
    return (
      <Router
        routes={this.props.routes}
        history={this.props.history} />
    )
  }

  render () {
     return (

       <div className="App">
         <div style={{ height: '100%' }}>
          <h2>Welcome to Vavavoom!</h2>
           {this.content}
         </div>
      </div>
     )
   }
}

export default App;
  • 2
    PropTypes is a separate library now. https://www.npmjs.com/package/prop-types – Adam Azad Jan 23 '18 at 06:37
  • Possible Duplicate of https://stackoverflow.com/questions/44071022/getting-react-not-defined-in-static-component-in-react/44071067#44071067 – Shubham Khatri Jan 23 '18 at 06:41
  • That's not helping – Sathwik Gangisetty Jan 23 '18 at 07:49
  • Thanks for the answer. I was copying an old example and ran into the same issues. It was saying that there was an error in bootstrap. I installed bootstrap too. > __webpack_require__ C:/Users/WillFilm4Food/Documents/GitHub/test2/webpack/bootstrap:781 – Richard S May 07 '19 at 16:15

2 Answers2

2

First of all, give up on importing PropTypes from react. It is deprecated.

Instead, start using import PropTypes from 'prop-types The rest should work the way you are using it.

nitte93
  • 1,820
  • 3
  • 26
  • 42
2

Don't know why but changing version of react-router": "^3.2.0 to react-router": "^3.0.0 and react-dom": "^16.2.0 to react-dom": "^15.3.2 solved my issue