哑组件可以使用/渲染 redux 容器组件吗? [英] Can a dumb component use/render redux container component?

查看:44
本文介绍了哑组件可以使用/渲染 redux 容器组件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Redux 的入门视频中我们看到页脚(一个愚蠢的组件)使用了 Filterlink(一个容器).

In the getting started video of Redux we see that the Footer (a dumb component) uses Filterlink (a container).

但是当我阅读这篇文章时,它似乎,但不是很清楚,只有容器才能使用/渲染容器.

But when I read this article, it seems, but not very clearly, that only containers should use/render containers.

对我来说,如果 Footer 使用 Filterlink(与 Redux 绑定),我不能在其他不使用 Redux 的项目中重用它.但也许这是个例外?也许只用于一个项目的硬编码哑组件可以吗?

For me, if Footer uses Filterlink (which is tied to Redux) I can't reuse it on other projects which don't use Redux. But maybe it is an exception? Maybe hard coding dumb component for use only on one project is ok?

我错过了什么吗?

推荐答案

这篇文章与我今天的想法有些过时.我刚刚更新了它,以便您可以以全新的视角再次阅读.我认为在展示组件中使用容器组件是完全没问题的.这样做的原因很简单:您希望能够在需要太多信息的任何时候将展示组件转换为容器组件,如果您在这样做时必须转换所有调用站点,那将是一个无赖.因此,一个组件是展示性的还是容器是它的实现细节,任何组件,无论是展示性的还是容器的,都可以很好地使用它.

The article was somewhat out of date with how I think about it today. I just updated it so you can read it again with the fresh perspective. I’ve come to the opinion that it’s totally fine to use container components inside presentational components. The reason for this is simple: you want to be able to turn a presentational component into a container component at any time it needs too much information, and it would be a bummer if you had to convert all call sites when you do that. Therefore whether a component is presentational or a container is its implementation detail, and any components, whether presentational or containers, can use it just fine.

这篇关于哑组件可以使用/渲染 redux 容器组件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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