Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React - Uncaught TypeError: Cannot read property 'func' of undefined

I'm receiving the error:

Uncaught TypeError: Cannot read property 'func' of undefined

Yet I have no idea why, I've Googled the error and gone to everyone post with the same error yet no luck. Can anyone help me out?

I'm using [email protected]

index.jsx

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import { Helmet } from 'react-helmet';

import Routes from './config/routes';

ReactDOM.render(
    <div>
        <Helmet>
            <meta charSet='utf-8'/>
            <title>Skelton</title>
            <link rel='icon' href='images/favicon.png'/>
            <link rel='stylesheet' href='style.css'/>
        </Helmet>
        <Router routes={Routes()} history={browserHistory}/>
    </div>
, document.getElementById('root'));

route.js

import React from 'react';
import { Route, IndexRoute } from 'react-router';

import Example1 from '../pages/Example1';

export function routes() {
    return (
        <Route>
            <Route path='/' component={Example1}/>
            <IndexRoute component={Example1}/>
        </Route>
    );
}

export default routes;

Example1.js

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

class Example1 extends Component {
    render() {
        return (
            <div>
                <h1>Hello World! This is Example 1.</h1>
            </div>
        );
    }
}

export default Example1;

Originally I didn't import PropTypes because I don't need it, yet.

like image 412
Edward Avatar asked Nov 08 '17 15:11

Edward


Video Answer


2 Answers

It looks like a react-router bug (related to prop types.) It's working on react-router 3.2.0

Check the issue here: https://github.com/ReactTraining/react-router/issues/5605

like image 65
Héctor Avatar answered Oct 09 '22 23:10

Héctor


It's very easy to resolve.

This is happening because you are using react-router version 2.0.0

Just enter "npm install --save [email protected]"

It should just work fine now.

like image 27
Nikhil Yadav Avatar answered Oct 09 '22 23:10

Nikhil Yadav