<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>React on Jake Worth</title><link>https://jakeworth.com/tags/react/</link><description>Recent content in React on Jake Worth</description><image><title>Jake Worth</title><url>https://jakeworth.com/twittercard.png</url><link>https://jakeworth.com/twittercard.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 01 Dec 2025 18:21:26 -0500</lastBuildDate><atom:link href="https://jakeworth.com/tags/react/index.xml" rel="self" type="application/rss+xml"/><item><title>Import React and React 17 JSX Transform</title><link>https://jakeworth.com/tils/import-react-and-react-17-jsx-transform/</link><pubDate>Mon, 01 Dec 2025 18:21:26 -0500</pubDate><guid>https://jakeworth.com/tils/import-react-and-react-17-jsx-transform/</guid><description>&lt;p&gt;I&amp;rsquo;ve written before about the two competing ways to import React, but after React 17, you don&amp;rsquo;t need either.&lt;/p&gt;</description></item><item><title>Re-render Child Component By Changing Key</title><link>https://jakeworth.com/tils/rerender-child-component-by-changing-key/</link><pubDate>Tue, 05 Mar 2024 13:29:38 -0500</pubDate><guid>https://jakeworth.com/tils/rerender-child-component-by-changing-key/</guid><description>&lt;p&gt;Today I had a situation where I wanted a child component to re-render on
command. The solution I found was to to put a key on it, and then change the
key when the re-render is desired.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-tsx" data-lang="tsx"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;Parent&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; () &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; [&lt;span style="color:#a6e22e"&gt;childKey&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;setChildKey&lt;/span&gt;] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;useState&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;const&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;rerenderForm&lt;/span&gt; &lt;span style="color:#f92672"&gt;=&lt;/span&gt; () &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;setChildKey&lt;/span&gt;(&lt;span style="color:#a6e22e"&gt;childKey&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;button&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;onClick&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#a6e22e"&gt;rerenderForm&lt;/span&gt;} &lt;span style="color:#a6e22e"&gt;type&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;button&amp;#34;&lt;/span&gt;&amp;gt;&lt;span style="color:#a6e22e"&gt;Rerender&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;the&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;form&lt;/span&gt;&lt;span style="color:#f92672"&gt;!&lt;/span&gt;&amp;lt;/&lt;span style="color:#f92672"&gt;button&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;Form&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;key&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#a6e22e"&gt;childKey&lt;/span&gt;} /&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;/&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; )
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this example, which the button is clicked, our &lt;code&gt;childKey&lt;/code&gt; is incremented. To
paraphrase the React docs, when the key changes, React &amp;ldquo;loses track&amp;rdquo; of the
form. And because of the new key, at the same time React sees a new form; a
re-render has occurred.&lt;/p&gt;</description></item><item><title>Conditional Props</title><link>https://jakeworth.com/tils/conditional-props/</link><pubDate>Thu, 22 Feb 2024 11:42:56 -0500</pubDate><guid>https://jakeworth.com/tils/conditional-props/</guid><description>&lt;p&gt;Passing props conditionally a component makes sense in many situations. Imagine
a select box that receives an &lt;code&gt;isDisabled&lt;/code&gt; prop that disables the
input. Maybe we only want to set it if it&amp;rsquo;s true. For one, it&amp;rsquo;s a bit cleaner
than setting it to its default &lt;code&gt;false&lt;/code&gt; much of the time. And maybe we want to
select a certain default value in that same scenario.&lt;/p&gt;
&lt;p&gt;Enough theorizing! Here&amp;rsquo;s the code:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-tsx" data-lang="tsx"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;Select&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;options&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#a6e22e"&gt;itemOptions&lt;/span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&lt;span style="color:#a6e22e"&gt;...&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;(&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;someCondition&lt;/span&gt; &lt;span style="color:#960050;background-color:#1e0010"&gt;&amp;amp;&amp;amp;&lt;/span&gt; { &lt;span style="color:#a6e22e"&gt;isDisabled&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;:&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;true&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;defaultValue&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;:&lt;/span&gt; &lt;span style="color:#960050;background-color:#1e0010"&gt;[&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;itemOptions&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;[&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;0&lt;/span&gt;&lt;span style="color:#960050;background-color:#1e0010"&gt;]]&lt;/span&gt; }&lt;span style="color:#960050;background-color:#1e0010"&gt;)&lt;/span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let me explain the magic.&lt;/p&gt;</description></item><item><title>Join React Components With Comma</title><link>https://jakeworth.com/tils/join-react-components-with-comma/</link><pubDate>Thu, 22 Feb 2024 11:24:35 -0500</pubDate><guid>https://jakeworth.com/tils/join-react-components-with-comma/</guid><description>&lt;p&gt;Want to connect a list of React components with a delimiter, like a comma? Imagine a sentence of:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Link A, Link B, Link C.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;How could we programmatically achieve this in React?&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s one answer, inserting a comma before all but the first list item:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-tsx" data-lang="tsx"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&lt;span style="color:#a6e22e"&gt;items&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;map&lt;/span&gt;((&lt;span style="color:#a6e22e"&gt;item&lt;/span&gt;, &lt;span style="color:#a6e22e"&gt;index&lt;/span&gt;) &lt;span style="color:#f92672"&gt;=&amp;gt;&lt;/span&gt; (
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;React.Fragment&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;key&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#a6e22e"&gt;item&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;id&lt;/span&gt;}&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&lt;span style="color:#a6e22e"&gt;index&lt;/span&gt; &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt; &lt;span style="color:#f92672"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;, &amp;#39;&lt;/span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#f92672"&gt;a&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;href&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;`/items/&lt;/span&gt;&lt;span style="color:#e6db74"&gt;${&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;item&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;id&lt;/span&gt;&lt;span style="color:#e6db74"&gt;}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;`&lt;/span&gt;}&amp;gt;{&lt;span style="color:#a6e22e"&gt;item&lt;/span&gt;.&lt;span style="color:#a6e22e"&gt;name&lt;/span&gt;}&amp;lt;/&lt;span style="color:#f92672"&gt;a&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;/&lt;span style="color:#f92672"&gt;React.Fragment&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;))}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lots of other good suggestions in &lt;a href="https://gist.github.com/granmoe/274c299b792b039deecfb619753ea32c"&gt;this Gist&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Link Externally With React Router's Link</title><link>https://jakeworth.com/tils/link-externally-with-react-routers-link/</link><pubDate>Fri, 15 Dec 2023 11:45:30 -0500</pubDate><guid>https://jakeworth.com/tils/link-externally-with-react-routers-link/</guid><description>&lt;p&gt;React Router&amp;rsquo;s &lt;code&gt;Link&lt;/code&gt; component isn&amp;rsquo;t just for internal links; it can work like
an anchor tag, too, sending users outside the application. Use &lt;code&gt;reloadDocument&lt;/code&gt;
prop to get this behavior.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-tsx" data-lang="tsx"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;&lt;span style="color:#f92672"&gt;Link&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;reloadDocument&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;to&lt;/span&gt;&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{&lt;span style="color:#e6db74"&gt;&amp;#39;https://reactrouter.com/en/main/components/link&amp;#39;&lt;/span&gt;}&amp;gt;&lt;span style="color:#a6e22e"&gt;Link&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;docs&lt;/span&gt;&amp;lt;/&lt;span style="color:#f92672"&gt;Link&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="https://reactrouter.com/en/main/components/link"&gt;docs&lt;/a&gt;&lt;/p&gt;</description></item><item><title>How to Create a Timer or Polling in React with setInterval</title><link>https://jakeworth.com/posts/how-to-create-a-simple-timer-in-react-with-setinterval/</link><pubDate>Thu, 29 Dec 2022 00:00:00 +0000</pubDate><guid>https://jakeworth.com/posts/how-to-create-a-simple-timer-in-react-with-setinterval/</guid><description>&lt;p&gt;Have you ever wanted to create a timer in a React app? This could be in support
of a UI timer or polling. In this post, I&amp;rsquo;ll explain how to create a timer
effect in a React application using hooks and &lt;code&gt;setInterval&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>What Are the Tradeoffs of Passing Objects as React Props?</title><link>https://jakeworth.com/posts/objects-as-props/</link><pubDate>Mon, 27 Jun 2022 00:00:00 +0000</pubDate><guid>https://jakeworth.com/posts/objects-as-props/</guid><description>&lt;p&gt;A common React pattern is to pass an object as a &lt;a href="https://reactjs.org/docs/components-and-props.html"&gt;prop&lt;/a&gt;. Let&amp;rsquo;s consider the ways this can be used and tradeoffs of each.&lt;/p&gt;</description></item><item><title>Organizing React Components</title><link>https://jakeworth.com/posts/organizing-react-components/</link><pubDate>Mon, 23 May 2022 00:00:00 +0000</pubDate><guid>https://jakeworth.com/posts/organizing-react-components/</guid><description>&lt;p&gt;You&amp;rsquo;re creating a React app, and want to organize your components. Or maybe
you&amp;rsquo;re working in a legacy codebase, with many components in one directory, and
you want to better organize them. In this post, I&amp;rsquo;ll document an approach to
this problem that has worked for me.&lt;/p&gt;</description></item><item><title>Clear React Router's Location State</title><link>https://jakeworth.com/tils/clear-react-routers-location-state-from-the-console/</link><pubDate>Thu, 02 Sep 2021 11:32:04 -0400</pubDate><guid>https://jakeworth.com/tils/clear-react-routers-location-state-from-the-console/</guid><description>&lt;p&gt;The return of React Router&amp;rsquo;s &lt;code&gt;useLocation&lt;/code&gt; hook has a key called &lt;code&gt;state&lt;/code&gt; which
contains values passed during a redirect or navigation. But where is that state
stored by the browser, and how do we clear it?&lt;/p&gt;</description></item></channel></rss>