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

前端 未结 1 1357
离开以前
离开以前 2021-02-15 17:29

I can\'t figure out how to access a method from a parent ReactJS component within my post route and component. Using react-router.

This is in

1条回答
  •  梦如初夏
    2021-02-15 18:16

    Move pushToPostList={this.pushToPostList} to the App Class.

    var App = React.createClass({
    
    getInitialState: function() {
        return {
            myList: []
        };
    },
    
    pushToPostList: function (object) {
        if (object) { 
          var myTempPosts = this.state.myPostList;
          myTempPosts.push(object); 
          this.setState( {myPostList: myTempPosts} );
        }
    },
    
    render: function() {        
        return (
            
    ); } });

    0 讨论(0)
提交回复
热议问题