[英]Recursive rendering of React component connected to Redux store
是否可以递归渲染React组件连接到Redux存储?
示例(在我的情况下,没有机会进行无限组件渲染循环):
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)
我看到我可以在组件中渲染组件,但嵌套组件没有连接到商店,并且我没有需要this.props.data
。
是否有机会将嵌套组件连接到商店?
尝试渲染已连接的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.