React router and this.props.children - how to pass state to this.props.children

前端 未结 3 1159
醉酒成梦
醉酒成梦 2020-12-01 10:21

I\'m using React-router for the first time and I don\'t know how to think in it yet. Here\'s how i\'m loading my components in nested routes.

entry point .js

3条回答
  •  一生所求
    2020-12-01 11:21

    You can use the React method "cloneElement" to accomplish this. When you clone the element, you can pass in props at that time. Use the clone instead of the original in your render fn. eg:

        render: function() {
        var childrenWithProps = React.cloneElement(this.props.children, {someProp: this.state.someProp});
        return (
          
    {childrenWithProps}
    ); }

提交回复
热议问题