reactjs - Using React contextTypes with react-router -


i know it's rather undocumented feature, since react-router has no clean way of passing props child route components, wanted use context.

<router history={history}>     <route component={application} path="/(:id)">         <indexroute component={editdocument} />     </route> </router>  class application extends component {      static childcontexttypes = {         charts: pt.array.isrequired,     }      getchildcontext() {         return { charts: this.getcharts() };     }      render() {         return <div>{this.props.children}</div>     } }  class editdocument extends component {      static contexttypes = {         charts: pt.array.isrequired,     }      componentwillmount() {         this.context.charts === undefined     } } 

i using react 0.13 now. can solved using 0.14?

you try {react.cloneelement(this.props.children, {someextraprop: })}

so pass additional stuff views

e.g.

function renderapp(data) {  var react = require('react'); var reactrouter = require('react-router'); var router = reactrouter.router;  var app = react.createclass({  render: function () {    return (  <appshell>          {react.cloneelement(this.props.children, {data:data})}      </appshell>   ); } });  var rootroute = { component: 'div', childroutes: [{ path: '/', component: {app}, ///etc }] };  react.render( 

react.render(

 <router routes={rootroute}/>, document.body 

);

, document.body );  } renderapp(data); 

hope that.s useful, let me know if need explain better


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -