reactjs - How to pass both this.state and this.props to routes using react-router -



reactjs - How to pass both this.state and this.props to routes using react-router -

i can't figure out how access method parent reactjs component within post route , component. using react-router.

this in <routehandler {...this.state} />

the method/function pushtopostlist() in adds post object array, held in this.state.mylist.

trying <post /> component working calls this.props.pushtopostlist(newpost) update this.state.mylist in <app />

router is:

var routes = ( <route handler={app} > <defaultroute handler={signup} /> <route name="feed" path="feed" handler={latestfeed} /> <route name="post" path="post" handler={post} pushtopostlist={this.pushtopostlist} /> </route> ); router.run(routes, function (handler) { react.render(<handler />, document.body ); });

more code:

var app = react.createclass({ getinitialstate: function() { homecoming { mylist: [] }; }, pushtopostlist: function (object) { if (object) { var mytempposts = this.state.mypostlist; mytempposts.push(object); this.setstate( {mypostlist: mytempposts} ); } }, render: function() { homecoming ( <div> <routehandler {...this.state} /> </div> ); } }); var post = react.createclass({ handlesubmit: function(e) { e.preventdefault(); var myposttxt = this.refs.myposttxt.getdomnode().value.trim(); this.props.pushtopostlist( myposttxt ); // send object parent reactjs component. }, render: function() { homecoming ( <div> post. <textarea ref="myposttxt" /> <p /> <button onclick={this.handlesubmit} type="submit">post</button> </div> ); } });

move pushtopostlist={this.pushtopostlist} app class.

var app = react.createclass({ getinitialstate: function() { homecoming { mylist: [] }; }, pushtopostlist: function (object) { if (object) { var mytempposts = this.state.mypostlist; mytempposts.push(object); this.setstate( {mypostlist: mytempposts} ); } }, render: function() { homecoming ( <div> <routehandler {...this.state} pushtopostlist={this.pushtopostlist} /> </div> ); } });

reactjs react-router

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -