<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Srigayatri on Medium]]></title>
        <description><![CDATA[Stories by Srigayatri on Medium]]></description>
        <link>https://medium.com/@srigayatri786?source=rss-19c880d27250------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RGJ5kjKyZkEzj9yJ7roRyQ.jpeg</url>
            <title>Stories by Srigayatri on Medium</title>
            <link>https://medium.com/@srigayatri786?source=rss-19c880d27250------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:00:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srigayatri786/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Presentational & Container Components — When to Use What]]></title>
            <link>https://medium.com/prod-io/presentational-container-components-when-to-use-what-99be8fa28953?source=rss-19c880d27250------2</link>
            <guid isPermaLink="false">https://medium.com/p/99be8fa28953</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Srigayatri]]></dc:creator>
            <pubDate>Fri, 23 Jun 2017 12:44:03 GMT</pubDate>
            <atom:updated>2017-07-11T13:54:17.039Z</atom:updated>
            <content:encoded><![CDATA[<p>One design pattern which I find very useful in building complex React and Redux projects is using “Presentational and Container Components”.</p><p>Let’s start with the basic definitions of these components:</p><h3>Presentational Components:</h3><ul><li>Deal with only the look and feel of the component.</li><li>No access to the state (store). Any state being used is its UI state. (Rule of thumb: Most presentational components need not use its state).</li></ul><h3>Container Components:</h3><ul><li>These are the components which deal with how things work.</li><li>They access the state of the application.</li><li>They access the actions which change the state of the application.</li></ul><h3>Advantages of Dividing Components into Container and Presentational Components:</h3><ul><li>Separation of Concerns</li><li>Reusability of presentational components</li></ul><p>When I started coding in React for the first time, I started with a complex project with a single container and several presentational components. Whenever I had to make a change to any component, I had to keep passing down the props from the container down to the last presentational component which used it.</p><p>My container component also became very bulky and knew too much about every presentational component. I wasn’t getting much advantage of the separation of concerns.</p><p>I then rewired my application to allow multiple container components within my application.</p><p>Let me explain it with an example:</p><h3>Application Definition:</h3><p>Consider a Tic-Tac-Toe game with 2 modes:</p><ul><li>play with friend</li><li>play with computer</li></ul><p>Once you click on the mode, you can choose to restart any game paused, or start a new game.</p><p>Each game has a timer. On click on the pause button, the timer will stop. On click on resume, the timer will start.</p><p>You can also leave the game at any time, and the game will be saved.</p><p>The division of the components would be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0lsFnJmYHc8VWRS65CwV9Q.png" /></figure><p>As you see, our Game component keeps passing props without ever using it. Let’s look at how our Container component looks like.</p><p>The Game Container component looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5966a25747a345017fc449a2b5e42c84/href">https://medium.com/media/5966a25747a345017fc449a2b5e42c84/href</a></iframe><p>The Game Container knows too much — it knows about the game modes, making a move, options to save and quit the game and about the analytics. If any other new requirement comes up, it would become very difficult to maintain it.</p><p>To optimise this, let’s change some of our presentational components into container components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VWOud8T96pTZYJWrPkn41g.png" /></figure><p>Our Container Components now look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9a2df1314e6dc82a955eeea5c94a394/href">https://medium.com/media/d9a2df1314e6dc82a955eeea5c94a394/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1dad0c60e859467e2840734ea7e0efd/href">https://medium.com/media/e1dad0c60e859467e2840734ea7e0efd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf005e10811ae64e1e03d5835600a600/href">https://medium.com/media/bf005e10811ae64e1e03d5835600a600/href</a></iframe><p>The individual containers are easier to understand and maintain.</p><p>If in the future, if the Tic Tac Toe Board, Timer or Quit Options become complicated we can make them each their individual containers.</p><h3>References:</h3><ul><li><a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">Presentational and Container Components</a></li><li><a href="https://jaketrent.com/post/smart-dumb-components-react/">Smart and Dumb Components in React</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99be8fa28953" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prod-io/presentational-container-components-when-to-use-what-99be8fa28953">Presentational &amp; Container Components — When to Use What</a> was originally published in <a href="https://medium.com/prod-io">Prod.IO</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>