reactjs - How does React Router get into the React context? -


i looking @ redux-blog-example. there signuproute.js looks this:

@connect(state => ({   auth: state.auth }), {   signup }) export default class signuproute extends react.component {   static contexttypes = {     router: react.proptypes.object   }    handlesubmit = (email, password) => {     const router = this.context.router;      this.props.signup(email, password, router);   }    render() {     return (         <signup           auth={this.props}           handlesubmit={this.handlesubmit}         />     );   } } 

how router wired context of class?

it uses context, undocumented quite implemented react feature. full lowdown see this article, here's gist of it:

let router = router(); // illustrating, not how instantiate react router  class mycomponent extends react.component {     static contexttypes = {         router: react.proptypes.object     };      render(){         // declaring context type here, , childcontexttypes         // on parent along function how it,         // react traverse , `router` context.         // inject `this.context`, making          // available here.     } }  class parent extends react.component {     static childcontexttypes = {         router: react.proptypes.object     };      getchildcontext(){       return {         router: this.props.router       };     }      render(){         return <mycomponent />;     } }  reactdom.render(<parent router={router} />, document.getelementbyid('app')); 

Comments