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 讓我實現同樣的需求,並沒有造成分裂。由於歷史原因,該文本保持不變,但不要太認真。

(……正文參考文末鏈接)


我認爲:容器型組件擁有狀態、分配狀態,展示型組件用以分層和複用,複用不是目的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章