[英]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.