[WP] 04.05.2023 | smart-dumb

fig 1.1 smart-dumb scheme

In this post I want to take a look at organization of components in web applications. During designing new parts of web application we may follow simple concept  of smart and dumb components. The aliases for above are fat and skinny components or presentational and container components.

Smart componetns contain the core logic of the application including querying database, fetching external resources or utilizing third-party libraries. It does not care about redux. This information is often contained within state and passed to the other parts of application via props drilling or by the means of context. There are few smart components within application. They mostly come as a single instances across the app.

On the other hand – dumb components recieve and display data recieved from smart component. They may contain some logic including state but it has only applied in the context of dumb component eg. It is strictly conected with display features of the user interface and its called contextual logic. This simple logic and displaying features may be injected in several places in application and contextual logic can be passed by props.

There are following examples of tasks carried out by fat components: fetching data from api, using redux store, contain callbacks often trigered from dumb components.

There are several reasons that justivy dividing components to smart and dumb. Firstly it helps to isolate responsibilities of each component. Core logic is separated from display logic and collected in one place. It it is a way to stick to SRP -single responsibility principle. Moreover simple presentational componetns are far more simple to test. No mock required. Pure dumb components may be shallow rendered and tested for rendered items. Good design of dumb components allow to reuse the code in several places with only props changed. Finally skinny components are great from designers point of view. They can be easily bundled within styleguide or stroybook and presented to the team/client.

Ready for action

gmarcin

Komentarze

Popularne posty z tego bloga

[WP] 23.06.2023 | subjects

15.07.2024 | simplicity

[WP] 05.06.2023 | angular-intro