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

 

相关文章:

  • 2021-06-20
  • 2021-12-04
  • 2021-07-14
  • 2022-01-01
  • 2021-07-15
  • 2021-11-13
  • 2022-01-03
  • 2021-12-20
猜你喜欢
  • 2022-02-27
  • 2021-05-30
  • 2021-11-26
  • 2021-09-08
  • 2022-03-07
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案