简体   繁体   English

连接到Redux存储的React组件的递归呈现

[英]Recursive rendering of React component connected to Redux store

Is it possible to recursive render React component connected to Redux store? 是否可以递归渲染React组件连接到Redux存储?

Example (in my case there is no chance to do infinite component rendering loop): 示例(在我的情况下,没有机会进行无限组件渲染循环):

class Container extends Component {
    render (){
        return (
            <div>
                {this.props.data}
                {this.props.dataKey ? <Container dataKey={'123'} /> : null}
            </div>
    }
}

const mapStateToProps = (state, props) => {
    return {
        data: getDataFromStore(state, props.dataKey}
    }
}

export default connect(mapStateToProps)(Container)

I saw that i can render component in component, but nested component have not connection to the store and hance i do not have required this.props.data . 我看到我可以在组件中渲染组件,但嵌套组件没有连接到商店,并且我没有需要this.props.data

Is any chance to get nested component connected to the store? 是否有机会将嵌套组件连接到商店?

Try to render already connected Container : 尝试渲染已连接的Container

class Container extends Component {
    render (){
        return (
            <div>
                {this.props.data}
                {this.props.dataKey ? <ConnectedContainer dataKey={'123'} /> : null}
            </div>
        );
    }
}

const mapStateToProps = (state, props) => {
    return {
        data: getDataFromStore(state, props.dataKey}
    }
}

const ConnectedContainer = connect(mapStateToProps)(Container);

export default ConnectedContainer;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM