<?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 Joel Turner on Medium]]></title>
        <description><![CDATA[Stories by Joel Turner on Medium]]></description>
        <link>https://medium.com/@joelmturner?source=rss-2238ff2df4be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rvK3Yd6KI56jE_lQxJqHBw.jpeg</url>
            <title>Stories by Joel Turner on Medium</title>
            <link>https://medium.com/@joelmturner?source=rss-2238ff2df4be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:06:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joelmturner/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[Build an Inline Edit Text Input With React Hooks]]></title>
            <link>https://medium.com/@joelmturner/build-an-inline-edit-text-input-with-react-hooks-8303e3b433ec?source=rss-2238ff2df4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/8303e3b433ec</guid>
            <category><![CDATA[input-field]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[inline-editor]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Joel Turner]]></dc:creator>
            <pubDate>Fri, 10 Jan 2020 06:06:04 GMT</pubDate>
            <atom:updated>2020-01-10T06:06:04.412Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/731/0*xdZ_UDB5QlknaLBO.png" /></figure><p>A nice feature in many apps is to edit a title or other text inline without leaving the context that we’re in.</p><p>Here’s what we’ll be building.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F6ql5m&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F6ql5m&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F6ql5m%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/74c1d64b9afe946bca2ae3ce8098fc0a/href">https://medium.com/media/74c1d64b9afe946bca2ae3ce8098fc0a/href</a></iframe><p>Let’s take a look at the requirements for this component.</p><ul><li>Must show text when in rest</li><li>Click on text to edit the text</li><li>Enter key to save</li><li>Esc key to exit without saving</li><li>Click outside to save</li></ul><p>Cool, let’s start by creating the resting state. We’re going to do some basic styling with CSS to help us.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e3d27cb1418fd809ace6cd572c33f3a/href">https://medium.com/media/4e3d27cb1418fd809ace6cd572c33f3a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4c7a806f42050e74bd815266ef94787/href">https://medium.com/media/d4c7a806f42050e74bd815266ef94787/href</a></iframe><p>This set is us up with a simple text component that displays our text. Now the trickery begins! We want to click on the text and have the input show up. Let’s create some state to track whether we’re at rest or active.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/174bb68811688e8e469060ebbd456736/href">https://medium.com/media/174bb68811688e8e469060ebbd456736/href</a></iframe><p>Cool, now we have some state to help us display/hide our text and input. We also need some state to track what is being typed in our input. Let’s add another useState to hold that text.</p><pre>const [<strong>inputValue</strong>, <strong>setInputValue</strong>] = useState(“”);</pre><p>Let’s hook this state up to our elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0f37c8ce3df04db7d80e2844fcad22b/href">https://medium.com/media/f0f37c8ce3df04db7d80e2844fcad22b/href</a></iframe><p>Alright, now we need to set up the saving and escaping of the text. We can do this with a useEffect and <a href="https://usehooks.com/useKeyPress/">useKeypress hook</a> that watch for a key click and take an action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57cc082785da3dd78e54bff7dd82a11f/href">https://medium.com/media/57cc082785da3dd78e54bff7dd82a11f/href</a></iframe><p>Next, we’ll add a useRef on the wrapping, span to help us tell if a click happened outside of the component. We&#39;re going to use the <a href="https://usehooks.com/useOnClickOutside/">useOnClickOutside hook</a> from <a href="https://usehooks.com/">useHooks.com</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/264241fe423b0c82f04a913b6d0825b6/href">https://medium.com/media/264241fe423b0c82f04a913b6d0825b6/href</a></iframe><p>We can help the user by focusing the input when they click on the text. To do this we can add a useRef on the input and a useEffect that watches to see if the input is active.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa60e20ce097be6ccc44c1df2c862274/href">https://medium.com/media/fa60e20ce097be6ccc44c1df2c862274/href</a></iframe><p>That was a lot of little parts. Let’s put it together to see what we have.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e25501f59b364f709c0b28a1161872a5/href">https://medium.com/media/e25501f59b364f709c0b28a1161872a5/href</a></iframe><p>It’s worth noting that input text may need to be sanitized before being saved. I’ve had good luck with <a href="https://github.com/cure53/DOMPurify">DOMPurify</a>.</p><p>That’s it! Go forth and edit!</p><p><em>Originally published at </em><a href="https://joelmturner.com/blog/inline-text-edit-react-hooks/"><em>https://joelmturner.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8303e3b433ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Tip: GraphQL Fragments in Gatsby]]></title>
            <link>https://medium.com/@joelmturner/quick-tip-graphql-fragments-in-gatsby-33dc229801c4?source=rss-2238ff2df4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/33dc229801c4</guid>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[quick-tips]]></category>
            <dc:creator><![CDATA[Joel Turner]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 05:50:46 GMT</pubDate>
            <atom:updated>2020-01-09T06:06:13.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vR6B4TmTNEGQrKKY.png" /></figure><p>GraphQL makes it easy to get exactly the data we need for a given component. There are many times when we end up using the same query or part of a query in multiple places. This is where <a href="https://graphql.org/learn/queries/#fragments">GraphQL Fragments</a> can help us.</p><p>To declare a fragment we can add fragment MyAwesomeFragment on BlogPost. The keyword fragment tells GraphQL that we&#39;re creating the fragment with the name, MyAwesomeFragment. And all of this is on the type BlogPost.</p><p>On my site, <a href="https://joelmturner.com/">joelmturner.com</a>, I have a few different places where I’m querying images for galleries. So instead of repeating the whole query in every variation across the site I can create a queries file and drop the repeated parts in there. Here’s an example of that in action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b3302a4897f4a275e1e7e547db93cce/href">https://medium.com/media/9b3302a4897f4a275e1e7e547db93cce/href</a></iframe><p>Then we can use them in our components with a page query or static query.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/975bedcab6b200b30d8bb9bb197217a8/href">https://medium.com/media/975bedcab6b200b30d8bb9bb197217a8/href</a></iframe><h3>Typing</h3><p>If you’re using TypeScript you can also drop the types for the fragments in the queries file so they’re all together.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59bd1cc91f8fc7d4d2d2f27469e90d32/href">https://medium.com/media/59bd1cc91f8fc7d4d2d2f27469e90d32/href</a></iframe><h3>Bonus</h3><p>Add an alias if you’re doing similar top-level requests. Here’s an example of my Instagram requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bde4b3a2f6d9f582fcd84df072c64ddc/href">https://medium.com/media/bde4b3a2f6d9f582fcd84df072c64ddc/href</a></iframe><p>Now we can grab that data like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/155b6ea00529d1dab3f3f54c073ea9c4/href">https://medium.com/media/155b6ea00529d1dab3f3f54c073ea9c4/href</a></iframe><p>Thanks, and please let me know if you found this useful!</p><p><em>Originally published at </em><a href="https://joelmturner.com/blog/quick-tip-graphql-fragments/"><em>https://joelmturner.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33dc229801c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Favorite Layout Components in React]]></title>
            <link>https://medium.com/@joelmturner/my-favorite-layout-components-in-react-afbe62552a3c?source=rss-2238ff2df4be------2</link>
            <guid isPermaLink="false">https://medium.com/p/afbe62552a3c</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[flexbox]]></category>
            <dc:creator><![CDATA[Joel Turner]]></dc:creator>
            <pubDate>Wed, 08 Jan 2020 05:13:13 GMT</pubDate>
            <atom:updated>2020-01-09T06:12:02.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="black rectangles on aligned vertically and horizontally on a blue background" src="https://cdn-images-1.medium.com/max/731/1*w4OJFjgH9c6IDQv10a2PhQ.png" /></figure><p>There are a few components that I use almost every day in development. They are used for layouts and are made from flexbox and CSS grid. On this site, I pass both of these down with the MdxProvider so all my pages and posts have access to them easily.</p><h3>Flexbox</h3><p>This one is by far my favorite. 90% of the time it works perfectly with the props given. It can easily be extended through styled-components, emotion’s css prop, or Theme UI’s sx prop for those few cases where I need something extra.</p><p>This is an opinionated way to build a Flexbox component. The idea is to have booleans for certain aspects of the spec to help speed up a composition.</p><p>Here’s a list of the current props for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49eb061991492a086286d698b8ee6979/href">https://medium.com/media/49eb061991492a086286d698b8ee6979/href</a></iframe><p>Here is some example usage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/484830eda55d6d24a3d94d6a6397a6ff/href">https://medium.com/media/484830eda55d6d24a3d94d6a6397a6ff/href</a></iframe><h3>Grid</h3><p>Grid is another one of my favorites and it’s also very opinionated to suit my needs. The idea is to use css grid to create layouts. Depending on the project it can align with a design grid.</p><p>This can be paired with Flexbox for some powerful layouts. Add the sx prop from Theme UI for some wonderful breakpoint awesomeness.</p><p>Let’s take a look at the props.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33330b8d63b15ae128accc40faa766ee/href">https://medium.com/media/33330b8d63b15ae128accc40faa766ee/href</a></iframe><p>Here’s an example of using it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/361e13ae45300f1541167111c414e052/href">https://medium.com/media/361e13ae45300f1541167111c414e052/href</a></iframe><h4>Examples</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fd9e1u&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fd9e1u&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fd9e1u%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/25d447aabb22675b2f9f393911720a13/href">https://medium.com/media/25d447aabb22675b2f9f393911720a13/href</a></iframe><p>I had used a column component that accepted different span amounts but I ended up not using it as much. I tend to add a span to the children through the sx prop or extending with styled-components.</p><p>I would love to hear about other layout components that people use/have built to make composing elements faster and easier. Please let me know if you have any that you like. Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afbe62552a3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>