Skip to content

Instantly share code, notes, and snippets.

View TimGraf's full-sized avatar
:shipit:
GSD

Tim Graf TimGraf

:shipit:
GSD
View GitHub Profile

Container vs Presentational Components

This pattern emerged in the React world circa 2015 and steadily gained traction, showing up in books like Pro React and Dan Abramov's post on Presentational vs Container Components. It is basically a separation of concerns between how data is presented (in markup) and how it is retrieved & shaped from the component's external source(s). Containers are much smaller files than the presentational components themselves and they represent a very tight coupling that is best for single use. Presentational components however, can and should be designed with the intent of being reused in a different context. By separating the logic that defines how data should look from logic that retrieving that data, you can better re-use the logic that defines its presentation.

Your markup components should state expectations of the data they require. PropTypes

@milessabin
milessabin / singleton-only.scala
Created June 6, 2016 11:04
Scala type which can only be extended by an object, not by a non-abstract type ...
scala> class Foo { self: Singleton => }
defined class Foo
scala> class Bar extends Foo
<console>:12: error: illegal inheritance;
self-type Bar does not conform to Foo's selftype Foo with Singleton
class Bar extends Foo
^
scala> object Bar extends Foo