javascript - Method in React component not rendering HTML -


hello new react , have having bit of trouble don't think should experiencing. have component has 2 methods first method test , second standard render. check out:

var projects = react.createclass({     test: function(){       return(           <h1>why</h1>         )     },     render: function(){        return (           <div classname="postwrapper">             <div id="projectsheader">               <h1>projects</h1>             </div>             <div id="projectsbody">               {this.test}             </div>           </div>          )     }   }); 

the problem when calling test method using {this.test} within projects component, nothing renders. want method available within component can render multiple items programmatically. doing wrong? since using react router don't know how pass children props when being rendered programmatically using {this.props.children}, tried within masterlayout component became stuck. i'll provide rest of code context, appreciated.

var masterlayout = react.createclass({   mixins: [history],    getinitialstate: function(){     return{       hello: {}     }   },   renderprojects: function(){       return(           <div>             <h1>this better work</h1>           </div>           )     },   render: function(){     return(         <div id="container">           <navigation />           <div id="content">             {this.props.children}           </div>         </div>       )    } });  var projects = react.createclass({     test: function(){       return(           <h1>why</h1>         )     },     render: function(){        return (           <div classname="postwrapper">             <div id="projectsheader">               <h1>projects</h1>             </div>             <div id="projectsbody">               {this.test}             </div>           </div>          )     }   });    var testpage = react.createclass({      render: function(){       return(           <div classname="postwrapper">             <div id="postheader">               <div id="titledate">                 <h2>this test blog title</h2>                 <span>1/1/2016</span>               </div>               <div id="testframe">               </div>             </div>             <div id="postbody">               <p>...</p>             </div>           </div>         )     }   })   var routes = (           <router history={history}>             <route path="/" component={masterlayout}>               <indexroute component={testpage}></indexroute>               <route path="/projects" component={projects}></route>             </route>           </router>   )    reactdom.render(routes, document.getelementbyid("app")); 

you not calling test; you're trying output function itself, not result of function. add () after this.test:

var projects = react.createclass({     test: function() {       return(           <h1>why</h1>         )     },     render: function() {       return (           <div classname="postwrapper">             <div id="projectsheader">               <h1>projects</h1>             </div>             <div id="projectsbody">               {this.test()}             </div>           </div>       )     } }); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -