reactjs / reactjs/react.dev

We have hooks, then still do we use Container components and Presentational components?

未关闭
#2,819 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

discussion
主要语言
JavaScript
星标
11.8k
派生
7.9k
平均合并
1 天 11 小时
30 天内合并 PR
11

描述

I think it is a bit confusing and maybe a doc or writing can explain the situation.

After we have hooks, do we still design our app into Container components and Presentational components? (Does it mean we should not divide up our app design into containers and presentational components?)

Or does it simply mean: in the past we use class components as containers with states, and function components as presentation components, and now we can use function components as both containers and presentational components, and the recommendation is still to divide our app design into containers and presentational component?

In the past, we can simply use class components ONLY and we could still divide our app design into containers and presentational components. So function component having state doesn't change that situation... the question is more like should we now still divide our app design into containers and presentational component? So nowadays we could still make container components using function components, and then, make presentational components and use function components to do that, and strictly do not use any hooks in them, because then they become stateful and therefore not just "presentational".

I think the short version of the question is: even with function components able to use states, should we still divide up our app into components that have states, and components that strictly do not have states and like "pure function" to present data?

@gaearon

https://stackoverflow.com/questions/60593403/for-reactjs-how-is-the-change-from-using-container-components-and-presentation

In the past, in ReactJS, one way was to divide our components into Container components and Presentational components, and even Dan Abramov wrote a note about it not any more the case if we can use Hooks now.

How should it be done now — how does Hooks solve the problem?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

阅读 issue 文本,以及链接的 Stack Overflow 问题和 Dan Abramov 的说明。完成的标准是为 React 文档编写一份有针对性的解释,回答 Hooks 是否会改变关于 container/presentational 组件的指导。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react
领域
documentation, frontend
Issue 类型
文档
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。