Presentational and Container Components/容器型组件、展示型组件(Dan Abramov)

Update from 2019:

I wrote this article a long time ago and my views have since evolved. In particular, I don’t suggest splitting your components like this anymore. If you find it natural in your codebase, this pattern can be handy. But I’ve seen it enforced without any necessity and with almost dogmatic fervor far too many times. The main reason I found it useful was because it let me separate complex stateful logic from other aspects of the component. Hooks let me do the same thing without an arbitrary division. This text is left intact for historical reasons but don’t take it too seriously.


2019年更新:

我很久以前写过这篇文章,我的观点已经发生了变化。特别是,我不建议再拆分这样的组件。如果您在代码库中发现它很自然,那么这种模式可以很方便。但是我已经看到它没有任何必要性。我发现它有用的主要原因是因为它让我将复杂的有状态逻辑与组件的其他方面分开。Hooks 让我实现同样的需求,并没有造成分裂。由于历史原因,该文本保持不变,但不要太认真。

(……正文参考文末链接)


我认为:容器型组件拥有状态、分配状态,展示型组件用以分层和复用,复用不是目的。

发布了110 篇原创文章 · 获赞 53 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/xianghongai/article/details/100136849
今日推荐