react redux:容器组合 [英] react redux: containers composition

查看:52
本文介绍了react redux:容器组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 React+Redux 应用程序,我来到了我的地步考虑在另一个容器内使用一个容器.我问自己是否这是一个很好的方法,即.这是一个好习惯,还是应该严格遵循 1 个容器包含多个组件的规则?

I am building an React+Redux application, I come to the point where I am considering to use a container inside another container. I am asking myself if this is a good approach, ie. is it good practice, or should we strictly follow the rule of 1 container with several components ?

推荐答案

让我引用 Dan Abramov 的文章关于展示组件和容器组件:

Let me quote Dan Abramov's article about presentational- and container- components:

当您注意到某些组件不使用它们接收到的 props 而只是将它们向下传递,并且您必须在子级需要更多数据时重新连接所有这些中间组件时,是引入一些容器组件的好时机.这样你就可以获取叶子组件的数据和行为道具,而不会增加树中间无关组件的负担.

When you notice that some components don’t use the props they receive but merely forward them down and you have to rewire all those intermediate components any time the children need more data, it’s a good time to introduce some container components. This way you can get the data and the behavior props to the leaf components without burdening the unrelated components in the middle of the tree.

...意味着如果你觉得有需要,可以在另一个容器组件中放置一个容器组件.

...meaning it is perfectly fine to have a container component inside another container component if you feel the need for it.

这篇关于react redux:容器组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆