Coding Concepts - Smart vs Dumb Components
Tags: beginners, javascript, webdev, programming
Published: 2019-07-25 14:24:52

---
title: Coding Concepts - Smart vs Dumb Components
published: true
description: Most people will know you should use different components when building an application, but knowing how to construct them, and giving them specific responsibilities is key.
tags: beginners, javascript, webdev, programming
series: Coding Concepts
cover_image: https://thepracticaldev.s3.amazonaws.com/i/yvfmcttx99sxsp7dds98.png
canonical_url: http://blog.designpuddle.com/web-development/smart-vs-dumb-components/

---

With JavaScript frameworks taking over our front end world, it's important to understand a few key principles that the major three frameworks push. When building a web-based application you'll be tasked with structuring how everything communicates.

Most people will be aware that you should use different components to adhere to <a href="https://en.wikipedia.org/wiki/SOLID">S.O.L.I.D principles</a>, avoiding repetition in your application, making changes and additional features quicker and easier to integrate into the current solution. The actual creation and interaction between those components can be seperated in a number of ways but the simplest for me is considering them as Smart or Dumb.
<h1><a class="anchor" href="https://dev.to/new#smart" name="smart"></a>Smart Components</h1>
<blockquote>Contains dependencies that are application-specific. Services are injected in the constructor of these containers.</blockquote>
Also known as <strong>Controller</strong> components or <strong>Container</strong> components that can:
<ul>
 	<li>Manipulate Data</li>
 	<li>Call out to external resources (libraries, APIs)</li>
 	<li>Manage State</li>
</ul>
In essence, these can be thought about as a container, page or section implementing a specific task of the user.
<h1><a class="anchor" href="https://dev.to/new#dumb" name="dumb"></a>Dumb Components</h1>
<blockquote>Recieves data and displays the information.</blockquote>
Also, know as <strong>Presentation</strong> components or <strong>Pure</strong> components that can:
<ul>
 	<li>Allow for data to be passed in</li>
 	<li>Display that data in a specific format and style</li>
</ul>
These can be thought of as where you create the final HTML and CSS for what something will look like on the screen. This is where you style your application and interact with the user.
<h1><a class="anchor" href="https://dev.to/new#interaction" name="interaction"></a>Interaction</h1>
A smart component will contain one or more dumb components within them. The smart components will pass the data they receive down into these presentation components which then render the data as required.

If there is any interaction required between a smart and dumb component then a event will be fired back up to the smart component to deal with.
<h1><a class="anchor" href="https://dev.to/new#purpose" name="purpose"></a>Purpose</h1>
So why do we need to separate our application this way? Well as in any form of programming, following specific paradigms or approaches is not strictly enforced or required to allow and application to function, but will usually have a number of benefits down the line.

<strong>Reusability</strong> is always heralded as a major benefit to most programming approaches. Following the D.R.Y principle of (Do)Not Repeating Yourself means that you can add the same functionality to different areas quickly and effectively.

<strong>Refactoring</strong> a part or whole of an application only requires changes in a smaller number of places.

<strong>Readability</strong> It's easier to read component names to figure out what something does rather than having to dissect reams of HTML!

<strong>Running Tests</strong> Last but not least, testing smaller self-contained components makes creating and managing your suite of tests easier.

Separating the concerns of your application across these two types of components, in whichever way you want to describe them should make the task of creating a web app in React, Vue or Angular a much nicer and easier process for all those involved.

If you feel differently, as <a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">Dan Abramov has recently done</a> then please feel free with sharing your opinions below.