React-router: Error: type specification of context router is invalid

Created on 2 Jul 2016  路  2Comments  路  Source: ReactTraining/react-router

I'm using version 2.4.1.

I have this warning that didn't appear on previous projects with a similar configuration. I didn't update any versions.

Warning: App: type specification of context router is invalid; the type checker function must return null or an Error but returned a function. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).

Here are the versions I'm using:

    "react": "^15.1.0",
    "react-dom": "^15.1.0",
    "react-router": "^2.4.1"

index.jsx

import React from 'react';
import { ReactDOM, render } from 'react-dom'
import { Router, Route, hashHistory, IndexRoute } from 'react-router'

import App from './components/App'

render((
  <Router history={hashHistory}>
    <Route path="/" component={App}>
    </Route>
  </Router>
), document.getElementById('app-react'))

App.jsx

import React from 'react'

export default class App extends React.Component{
    render(){
        return(
            <div>Hello World</div>
        )
    }
}

App.contextTypes = {
    router: () => {
        return React.PropTypes.func.isRequired
    }
}

I added contextTypes to be able to access context.router since I didn't find any other way of accessing the router from a component.

Is there anything obviously wrong here? If not please tell me and I will create a project you can clone.

Most helpful comment

Thanks, I solved it by using:

App.contextTypes = {
    router: React.PropTypes.object
}

All 2 comments

That's not how you specify context types. It's the same as prop types. Use just the type checker, not a function that returns the type checker.

Thanks, I solved it by using:

App.contextTypes = {
    router: React.PropTypes.object
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

maier-stefan picture maier-stefan  路  3Comments

alexyaseen picture alexyaseen  路  3Comments

stnwk picture stnwk  路  3Comments

wzup picture wzup  路  3Comments

andrewpillar picture andrewpillar  路  3Comments