<?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 Kerry Convery on Medium]]></title>
        <description><![CDATA[Stories by Kerry Convery on Medium]]></description>
        <link>https://medium.com/@kerry-convery?source=rss-6db7b8d6f98------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Kerry Convery on Medium</title>
            <link>https://medium.com/@kerry-convery?source=rss-6db7b8d6f98------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:03:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kerry-convery/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[Using CSS Grid to sandwich scrollable content been a page header and footer]]></title>
            <link>https://kerry-convery.medium.com/using-css-grid-to-sandwich-scrollable-content-been-a-page-header-and-footer-5f9fee3670dd?source=rss-6db7b8d6f98------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f9fee3670dd</guid>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[footer]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Kerry Convery]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 10:25:19 GMT</pubDate>
            <atom:updated>2021-04-29T10:25:19.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZZwUnUGsj5r1_aaS0E3DA.jpeg" /></figure><p>The other day I had a task to create a page that renders a scrollable list of items between a page header and footer.</p><p>The header and footer should stick to the top and bottom of the page, respectively. The list in the middle should display a scrollbar once the list becomes longer than the space it is allowed to occupy.</p><p>The page should also be responsive in that when the page height is changed the scrollable list should shrink or grow according to the amount of space available between the header and footer.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fkerryconvery%2Fembed%2Fpreview%2FxBdgra%3Fdefault-tabs%3Dhtml%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DxBdgra&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2Fkerryconvery%2Fpen%2FxBdgra&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad909521a8ee659c13e7fe47709103db/href">https://medium.com/media/ad909521a8ee659c13e7fe47709103db/href</a></iframe><p>It took a bit of figuring out but I was able to achieve the desired effect which I’d like to share in the hope that my learnings will help someone else.</p><p>The effect is broken up into three parts.</p><p>Firstly we define a CSS Grid with three rows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd248b3016ed7b32ab49d3b1829edc75/href">https://medium.com/media/fd248b3016ed7b32ab49d3b1829edc75/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54b7ecba8123717f489654e948aba21a/href">https://medium.com/media/54b7ecba8123717f489654e948aba21a/href</a></iframe><p>The first and third rows define the page title and page footer sections, respectively. They are of size auto which means that they will resize to fit the content.</p><p>The second row is where we will place the scrollable content. It is of size 1fr so that it fills the page space that is not taken by the first and third rows; row gaps are also taken into account. You can read more about the fr unit <a href="https://css-tricks.com/introduction-fr-css-unit/">here</a>.</p><p>Note that we have set the element’s high, the body height and the grid’s minimum height to 100% so that the grid takes up 100% of the page height. This is important to push the footer to the bottom.</p><p>Next, the real magic begins</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b57b68e64955aff96cccf909b84e6e23/href">https://medium.com/media/b57b68e64955aff96cccf909b84e6e23/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2845c7b2d2167fdda9c0dedceda7b1c2/href">https://medium.com/media/2845c7b2d2167fdda9c0dedceda7b1c2/href</a></iframe><p>I have introduced a new CSS class called scrollable-content. This is where your list of items will go.</p><p>In the page_content class, I have set the overflow-y property to “auto” so that a scrollbar will be displayed, but only if needed. I’ve also set the position property to “relative” which means that it will be positioned relative to itself. Since we have not specified any positional properties (top, left), it will be positioned as if the position was set to static, that is, where it would normally be placed according to the natural flow of elements.</p><p>But why have we done this? Giving an element a position of relative lets us use the “absolute” position in child elements; I’ve set this in the scrollable_content class.</p><p>Setting position to absolute does two things, firstly it positions the element within the nearest containing block. Secondly, it removes the element from the normal flow. It is the latter that we are interested in.</p><p>Removing an element from the normal flow means that it will not affect the position of other elements (and itself will not be affected by other elements) which means it can grow without stretching the containing element and therefore will not push the footer off the page. Instead, it simply grows inside the containing element causing it to display a scrollbar.</p><h4><strong>Conclusion</strong></h4><p>There we have it, clean and simple. For my purpose, I’ve tested this in the latest versions of Chrome, Firefox, Safari, and Edge but to ensure browser compatibility, especially with older browsers, it would be prudent to do your own testing and make adjustments as necessary.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f9fee3670dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React testing simplified with humble components.]]></title>
            <link>https://kerry-convery.medium.com/react-testing-simplified-with-humble-components-ac40ae558031?source=rss-6db7b8d6f98------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac40ae558031</guid>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[side-effects]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kerry Convery]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 11:45:28 GMT</pubDate>
            <atom:updated>2021-04-12T23:09:48.340Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVVz_yvIiU2Tn59NmaEAtg.jpeg" /></figure><p>React components can contain a mix of logic state and side effects. With the React hooks, it is now possible to turn once pure functional components into impure ones.</p><p>When it comes to unit testing we know that testing a pure function is easier than testing an impure one, the same applies to React components which after all, can be built from simple functions.</p><p>Consider the following component, BookList</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57e803a8c9e4b65a1cd4ff0cc000908a/href">https://medium.com/media/57e803a8c9e4b65a1cd4ff0cc000908a/href</a></iframe><p>It’s simple enough so let’s take a look at how we might test it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/627d299fba61b7630571c06959bfb8a6/href">https://medium.com/media/627d299fba61b7630571c06959bfb8a6/href</a></iframe><p>BookList is an impure functional component because it fetches data from an external source. The tests are relatively clean and simple even though we’ve had to stub fetch (or use mock service worker) to fake the API call. Can we do better? Yes, we can, by using the humble object pattern.</p><p>The humble object pattern helps improve testability by separating logic from side effects. Side effects are moved into a simple, humble object which does nothing but invoke the side effect and the function containing the logic.</p><p>Let&#39;s see how we can create a humble component using the humble object pattern.</p><p>First, let us create a pure component called BookListView that contains our logic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a79ffda2ea62f7f116050bf7a45c618/href">https://medium.com/media/1a79ffda2ea62f7f116050bf7a45c618/href</a></iframe><p>BookList has become a humble component containing only the API service call and some state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d178e80391f7e0ad4943ab8b00705c4f/href">https://medium.com/media/d178e80391f7e0ad4943ab8b00705c4f/href</a></iframe><p>And now the tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/808733c0e723aa5aa175d53cc179413f/href">https://medium.com/media/808733c0e723aa5aa175d53cc179413f/href</a></iframe><p>Notice that the tests are much simpler now. However, we haven’t tested the BookList. That is because we can cover this component with end-to-end UI tests to ensure that everything is hooked up correctly.</p><p>We have made testing the component’s logic easier however there is still a problem. What happens if we were to use the BookList component inside another pure component? The pure component will become impure and we are back to mocking and stubbing again. 🤔</p><p>To fix this we can use the component composition techniques described <a href="https://reactjs.org/docs/composition-vs-inheritance.html">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e53872f2ab7fd839a4b32bfb2c62b180/href">https://medium.com/media/e53872f2ab7fd839a4b32bfb2c62b180/href</a></iframe><p>And we can compose the impure BookList component with our pure one Pager without breaking its purity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b1ca48b85e35412947b3b123a3c923c/href">https://medium.com/media/5b1ca48b85e35412947b3b123a3c923c/href</a></iframe><p>Again this can be testing using end-to-end testing to ensure that a list of books is rendered and that you can click on a page number to get the next page of books while allowing more fine-grained unit tests to be performed on the Pager component itself.</p><h3>Conclusion</h3><p>Pure components are easier to test than impure ones so we should strive to keep our components pure whenever possible. Here we have used the humble object pattern to create a humble component called BookList which is free from logic. We’ve also seen how pure components can consume impure ones while maintaining their purity. This reminds me of container and view components, only the difference is that container components often contained logic as well as side effects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac40ae558031" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Techniques for reducing prop drilling in React]]></title>
            <link>https://kerry-convery.medium.com/techniques-for-reducing-prop-drilling-in-react-bf3fdd6fc7a1?source=rss-6db7b8d6f98------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf3fdd6fc7a1</guid>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[drilling]]></category>
            <category><![CDATA[props]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Kerry Convery]]></dc:creator>
            <pubDate>Sat, 13 Mar 2021 11:31:47 GMT</pubDate>
            <atom:updated>2021-03-13T22:50:03.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGy2EQTZl0IWm_iairg3Nw.jpeg" /></figure><p>I went on a bit of a journey to discover different techniques used to reduce the need to prop drill. Here I outline each of what I’ve found to be the dominant methods used and my thoughts on each of them.</p><p>Prop drilling is the result of having to pass props between multiple components that are not using them directly but mealy passing them to child components until finally reaching a component that uses them. However, props are the main mechanism by which data is passed between components so prop drilling in itself is not necessarily a bad thing.</p><p>The issues come about when you need to add or remove a prop from a component and you need to work your back up the tree, updating all of the components in between; sounds like a lot of work right? Not only that, what if you make a mistake and don’t update all of the components in the tree? You’ll be either passing a removed prop unnecessarily or not passing a newly added prop which could result in either making it more difficult to know which props are actually used or worse passing undefined to a component.</p><p>Now in the case of not passing a prop, if you have defined required prop types, React will warn you that a prop is missing but you still have to figure out from where in the tree it’s not being passed from and then pass it down to the component that needs it. It boils down to more effort to update the tree and more effort to debug components.</p><blockquote><em>Prop drilling is an inherent part of React, it is its main mechanism for passing data between components.</em></blockquote><p>Several solutions have been put forward which reduce the need to pass props through man layers. Let&#39;s have a look at them in more detail to get an idea of why we might choose one method over another.</p><h3>React Context</h3><p>Using the React context API to pass props to lower components indirectly, thereby bypassing any components in between. This may seem like a good idea at first however in my view there are two issues with this approach.</p><p>Firstly it violates function honesty in that the signature of a React functional component is dishonest about what data the component needs to be passed in order to operate. Dishonest functions force you to dig down into the component code to understand what data it needs, and in the case of the context API, how to pass data to it.</p><p>Secondly, to test the component, you will need to wrap the system under test (SUT) in a provider component that is responsible for injecting the required data into the context. This in turn increases the amount of code you need to write to test what should be a simple and pure component. This can become especially painful if you have several nested components, each requiring different data from context and each having its own provider.</p><p>It starts to get out of control when you can no longer tell, at a glance, which provider is supplying data to which components.</p><p>You can mitigate some of this by separating visual components from non-visual container components. The container components receive the context and then pass the props into the visual components in the usual way. This allows you to unit test your visual components without needing to supply a provider component. You can cover the interaction between the visual and container components with an integration test. However, this will increase the number of components that you need to manage and therefore increase the complexity of the code base and size of the bundle.</p><p>Using React context in this way is also considered as an option of last resort by the React team so consider carefully before you decide to go this route; It is often the case that there is a better way.</p><h3>Shallow Components</h3><p>This is a solution put forward by Kent C Dodds which you can read more about <a href="https://kentcdodds.com/blog/prop-drilling/">here</a>.</p><p>In a nutshell, this means simply not to create too many nested components by breaking up components unnecessarily and also by keeping the state close to the component(s) that actually use it. I think this is good advice and follows on to topics such as when should you break up components and how small is too small.</p><p>There is nothing wrong with having a large component as long as it has only one reason to change and it is not causing problems with maintenance, readability, testing, reusability, and performance. Prematurely breaking up components would also be considered a violation of YAGNI if there is no clear reason for it.</p><p>However, the challenge with this approach is that as applications grow in complexity it becomes increasingly difficult to keep components shallow. As you being to create more and more reusable components you inevitably end up with more and more layers. The next solution, Component Composition, can help us compose components together without creating additional layers.</p><h3>Component Composition</h3><p>Using composition in the way described in the React docs feels like the most natural way to minimise prop drilling. You can read more about component composition patterns <a href="https://reactjs.org/docs/composition-vs-inheritance.html">here</a></p><p>So how can it be used to reduce prop drilling? <a href="https://twitter.com/dan_abramov/status/1021850499618955272">This tweet </a>from Dan Abramov explains.</p><p>In a nutshell, you have props defined on a component that are used to pass in other components; also referred to as slots or pins.</p><p>We can write it as follows</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78637fe67d18ae3174d8565113060c9b/href">https://medium.com/media/78637fe67d18ae3174d8565113060c9b/href</a></iframe><p>Here “children” is a prop that React uses to pass anything that appears between the opening and closing JSX tags. Notice that I have also moved the InfiniateScoller component out of the ImageGalary component. I did this to show how multiple child components can be composed to completely remove prop drilling.</p><p>But what if you need to pass more than one component and they should be rendered in different places? You can simply provide your own custom props of type node as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/854eaa1a93a4be34ab296ccfc8449859/href">https://medium.com/media/854eaa1a93a4be34ab296ccfc8449859/href</a></iframe><p>The page component is free to position the passed-in components where it needs to and we do not need to drill the props through multiple components.</p><p>This is obviously a contrived example and I could have left InfiniateScoller inside the ImageGalary or even moved it to ImagePicker and I would only need to prop drill down one level, which to me is perfectly fine. I could even have moved the loading of images and state into ImagePicker, which together with also containing InfiniateScoller, would mean that I wouldn’t need to drill props at all.</p><p>Designing components so that they can be composed in this way makes them more flexible. I can replace any of the passed components with other components without modifying ImagePicker or ImageGalary. The downside is that composing components in this way in some cases could lead to deep JSX nesting within a component and reduced readability. To solve this one could allow one or even two levels of prop drilling and compose components such as InfiniteImageGalary or PagedImageGalary which is the composition of the ImageGalary component plus a component to handle paging.</p><p>This method of using props to allow composition is also useful for creating template components. Consider this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b320b1a6989ddc680da0e753dd65fdd8/href">https://medium.com/media/b320b1a6989ddc680da0e753dd65fdd8/href</a></iframe><p>The PageTemplate can be reused to set the layout of all pages within an application.</p><p>There is a similar method called render props. However, this is not the same as render props and solves a different problem. Render props are props that are defined as functions that return JSX and are meant as a more elegant solution to higher-order components.</p><h3>Conclusion</h3><p>Prop drilling can be considered more of a smell than an anti-pattern and also comes down to how many levels you are comfortable passing props down. The solutions presented above allow one to reduce or even eliminate the need to pass props down through multiple components.</p><p>In my opinion, effective use of component composition along with the thoughtful design is the best way to keep your components shallow thereby improving readability and also reducing prop drilling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf3fdd6fc7a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>