[JS Pattern] Container / Presentational Pattern

发布时间:2022-06-25 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了[JS Pattern] Container / Presentational Pattern脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Presnetational Component:

A presentational compoentn receives its data through props. It's primary function is to simply display the data it receives the way we want them to, including sytles, without modiying that data.

[JS Pattern] Container / Presentational Pattern

 

Container Component:

Container component is to pass data to presentational component. Since they don't render anything themselves, they usually do not contain any styling either.

[JS Pattern] Container / Presentational Pattern

 

Hooks

In many cases, the Container / Presentational pattern can be replaced with React Hooks. The introduction of Hooks made it easy for developers to add statefulness without needing a container component to provide that state;

[JS Pattern] Container / Presentational Pattern

 

Pros / Cons

Pros: 

  1. Separation of concerns
  2. Resuable
  3. Modify presentational component is easy
  4. Testing is easy

Cons:

  1. With React Hooks, this pattern can easily be an overkill in smaller sized application

 

[Note]: From JS Patterns book

 

脚本宝典总结

以上是脚本宝典为你收集整理的[JS Pattern] Container / Presentational Pattern全部内容,希望文章能够帮你解决[JS Pattern] Container / Presentational Pattern所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: