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
routeris invalid; the type checker function must returnnullor anErrorbut 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.
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
}
Most helpful comment
Thanks, I solved it by using: