-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
this.context.router is undefined in ES6 class constructor #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
class MyComp extends React.Component{
constructor(props, context){
super(props);
context.router // will work
}
}
MyComp.contextTypes = {
router: React.PropTypes.func.isRequired
}; |
Fantastic. Thanks! |
should also note in the 1.0 API you don't need to ask for the router off of context. |
@ryanflorence can you explain and point to the api what you mean by you don't need to ask for the router off of the context. Does that mean you don't have to access the context by context.router? How else would you access the router? |
+1 for @juhaelee's question. Can we access the router somehow without using context if we're using the class syntax? Or @ryanflorence, did you mean we don't need context if we're using the mixin with the |
I'd also like some clarification about accessing router in 1.0 (when using ES6) |
I guess he was referring to #1173 . There's no implementation yet, so I'd just use context for now. |
this.context.router is accessible in getInitalState(), however, it is undefined in
My workaround is to do the init in componentDidMount(), however, that is weird...
The text was updated successfully, but these errors were encountered: