<?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"><channel><title><![CDATA[codyaprice.com RSS Feed]]></title><description><![CDATA[My personal website.]]></description><link>https://codyaprice.com</link><generator>GatsbyJS</generator><lastBuildDate>Thu, 18 Feb 2021 03:10:39 GMT</lastBuildDate><item><title><![CDATA[On Hobbies and Magic]]></title><description><![CDATA[Y'all ever have a hobby that seems magical?
I mean something that you genuinely enjoy, and it feels like one of those books you cannot put…]]></description><link>https://codyaprice.com/blog/on-hobbies-and-magic/</link><guid isPermaLink="false">https://codyaprice.com/blog/on-hobbies-and-magic/</guid><pubDate>Sun, 02 Aug 2020 09:57:53 GMT</pubDate><content:encoded>&lt;p&gt;Y&amp;#x27;all ever have a hobby that seems magical?
I mean something that you genuinely enjoy, and it feels like one of those books you cannot put down?
Mine is photography.
Specifically, my magical hobby is landscape photography.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;doped-up&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#doped-up&quot; aria-label=&quot;doped up permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Doped up&lt;/h2&gt;&lt;p&gt;I recall an unmistakable jolt of dopamine when I lived in a studio apartment in Westport, Missouri.
Armed with only a Pixel 2XL, I cherished moments that allowed me to capture my side projects in a crisp focus juxtaposed with a pleasant bokeh.
Take a two-year scroll through my Instagram feed, and you&amp;#x27;ll find the occasional, semi-reasonably composed photo with ample bokeh abuse.
I loved the portrait feature of the Pixel 2, but I rarely took headshots.
I have progressed since and use it sparingly.
However, my &amp;quot;daily-driver&amp;quot; continues to be that fantastic camera phone.&lt;/p&gt;&lt;p&gt;Many of y&amp;#x27;all are familiar with the season where I regularly swapped between the West Bottoms and our Kansas City home remodeling project.
I would joke with Kiley that I just pointed the camera while the Pixel did the real work.
I loved sharing our progress with everyone, but the real joy came from each snapshot saved within my camera roll.
I have an enormous cache of content that I have never shared with anyone, likely for a couple of reasons. &lt;/p&gt;&lt;p&gt;The first reason is that historically my primary channel for sharing has been Instagram, limiting me to ten photos per post.
I don&amp;#x27;t always want to blow up everyone&amp;#x27;s feed with chains of multiple ten-photo posts.
There&amp;#x27;s also some substance, integrity, and intent lost when too many things are shared concurrently.
I enjoy sharing photos, but more so when the content tells a story or is mysterious or intriguing.
During the remodel, I lived to hear feedback like, &amp;quot;You always show just enough to tease us.&amp;quot;
I hope to carry that spirit along through my landscape photography.&lt;/p&gt;&lt;p&gt;My photo cache grows exponentially, but I feel that it is typical with photography; you&amp;#x27;re always producing more than what you officially publish.
I don&amp;#x27;t share everything because I don&amp;#x27;t think most of my photos are worth sharing; some are just terrible, while others are duplicates or perhaps didn&amp;#x27;t make the cut of the ten-photo Instagram limit.
There are also limits to my daily driver.
My Pixel 2 takes fantastic pictures of subjects that are close, say within 20 feet.
However, anything past that proves challenging to capture any quality depth of field.
The digital zoom quickly introduces noise through pixelation, and the sensor struggles with overexposure.
There&amp;#x27;s no easy way to take RAW photos, which is exacerbated by the lack of expandable storage and communication dead zones.
Lately, I&amp;#x27;m more often than not left wanting more.
I see something incredible that I want to immortalize, but my camera phone cannot take the picture.
While I&amp;#x27;ve been pleased with where the Pixel 2 has taken me, it&amp;#x27;s time to step up to a professional mirrorless camera.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;pnwonderland&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#pnwonderland&quot; aria-label=&quot;pnwonderland permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PNWonderland&lt;/h2&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0018-on-hobbies-and-magic/images/enchanted-pnw.jpg&quot; alt=&quot;Bridge on trail to Trout Lake in the Alpine Lakes Wilderness&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Bridge on trail to Trout Lake in the Alpine Lakes Wilderness&lt;/figcaption&gt;&lt;p&gt;Since relocating to the enchanting Pacific Northwest earlier this year, the region has started to pour its spirit and essence into me; I am absorbing the caricature.
I am a software engineer who is a fresh (and very out-of-shape) hiker that dabbles in photography.
It&amp;#x27;s of no-fault because of my adventures through the captivating vistas and the fragrant and exalted pines that beg me to capture their beauty.
What once was an occasional activity has morphed into an all-out passion.
My downtime has turned into following every Instagram nature and photography account.
I have started to watch YouTube tutorials on composition, editing in Lightroom, and tips and tricks concerning the mirrorless camera I haven&amp;#x27;t even purchased.
I now work for the weekend, but only because it promises of opportunity to explore the next trail.
I have three reasons to get back in shape now: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;To be the best, healthiest man for my bride.&lt;/li&gt;&lt;li&gt;To be the best, healthiest father for my child.&lt;/li&gt;&lt;li&gt;To make it further into the wilderness.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Being engulfed in my pursuit means that I ignored my body and pushed myself too far.
Approaching 30 means pain and being injury prone (read as: it sucks, y&amp;#x27;all).
Today, I slow down and rest and write this post while my right hip and hip flexor heal.&lt;/p&gt;&lt;h2 id=&quot;circling-back&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#circling-back&quot; aria-label=&quot;circling back permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Circling Back&lt;/h2&gt;&lt;p&gt;I want to circle back on something.
I mentioned my downtime and what I have pursued: Instagram accounts and tutorials.
These Instagram accounts have been truly inspirational, and most of them are Pacific Northwest specific.
I long to take photos like them, hence the dive into photography and editing tutorials.
This decision has become a double-edged sword, however.&lt;/p&gt;&lt;p&gt;On the one hand, I have more knowledge and tools at my disposal to take better photos.
On the other, it has killed some of the magic because it can kind of feel like min-maxing.
If you&amp;#x27;re unfamiliar with the term, it&amp;#x27;s generally tied to role-playing games like Dungeons and Dragons or World of Warcraft.
The idea is to power up your character by maximizing specific stats and ignoring all others leaving with a glass cannon: outrageously powerful, yet brittle and unbalanced.
This strategy is rather dull and flat and takes the fun out of the game.&lt;/p&gt;&lt;h2 id=&quot;a-short-aside&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#a-short-aside&quot; aria-label=&quot;a short aside permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A Short Aside&lt;/h2&gt;&lt;p&gt;Years ago, I stopped at my grandmother&amp;#x27;s house, and cozy on the couch, she watched a movie.
I don&amp;#x27;t recall why I originally intended to go there, but I remember staying for the film.
It wasn&amp;#x27;t a spectacular movie, but enjoyable enough with a stellar cast, popcorn, and some quality time with grandma.
The Big Year, starred Jack Black, Steve Martin, and Owen &amp;quot;Wow&amp;quot; Wilson and was about competitive bird watching.
If that sounds boring, please don&amp;#x27;t close this tab or navigate away, there&amp;#x27;s a point I&amp;#x27;m trying to make.
From what I remember, Owen Wilson is the world&amp;#x27;s best bird watcher, while Jack Black is the new kid on the block trying to usurp Owen&amp;#x27;s throne.
He used to be a computer programmer but hopes that bird watching is the calling that will lead to his sense of purpose.
Owen, at the detriment of his marriage and plans of conceiving, obsessively pursues maintaining his title.
Jack Black is closing in on Owen&amp;#x27;s title but realizes there&amp;#x27;s more to life and drops out to pursue a relationship with someone he met while birding.
Owen ends up winning the title and breaking his record, but his wife leaves him.&lt;/p&gt;&lt;p&gt;It ends with Owen out bird watching alone in Asia and, with regret in his gaze, peering at a happy couple and child.
Owen&amp;#x27;s character was a min-maxing birding over his relationship with his ex-wife and realized too late what he had lost.
He let his hobby become his obsession, and he lost the meaning of everything else.
Owen became disillusioned when he realized that he threw away his relationship with his ex-wife for something he presumably no longer enjoys.&lt;/p&gt;&lt;h2 id=&quot;resonating&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#resonating&quot; aria-label=&quot;resonating permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Resonating&lt;/h2&gt;&lt;p&gt;Last week, I watched a video that described how to edit photos in Lightroom, a pretty standard practice when shooting in RAW.
Generally speaking, RAW images tend to look flat and require some (read as: as few as possible) edits to match what your eye perceives.
I want to preface my critique.
The content creator takes fantastic pictures and is successful in landscape photography. Their compositions are stunning; however, my gut and limited instinct say they tend to over-edit.
Some of their photos look too good; they appear fake like a science fiction panorama complete with soft, glowing subjects and liberal use of perspective distortion and unnatural colors.
I watched as they haphazardly dialed in the luminance and applied filters until the image echoed its original emotional intent.
This is the spirit of min-maxing. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;And that&amp;#x27;s what resonates with me. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I think I resonate with this because I want to take a purist and minimalist approach to landscape photography: beauty in simplicity.
By min-maxing picture features, you reduce the art from a passion to a job.
It takes the fun out of it.
I don&amp;#x27;t want to min-max supposed quality at the expense of the enjoyment and love for photography.
I don&amp;#x27;t want to take for granted the natural splendor of the world and ruin the magic.
I appreciate and cherish it all.&lt;/p&gt;&lt;p&gt;God made Earth perfectly beautiful, with no filter or editing needed.
Nature does not require me to interject with corrections and improvements to make a scene fantastical and appear out-of-this-world.
That doesn&amp;#x27;t mean I should publish RAW photos directly.
Instead, I should apply as few edits as possible to perfectly capture what God sculpted for us.
In a bleak and abysmal world climate, let&amp;#x27;s keep the magic around as long as we can.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Photography is an art; it is visual storytelling.
I intend to tell stories of the beauty and mysteries of nature.
I hope to captivate y&amp;#x27;all with the wonders of what I experience in the wilderness.
I want to continue to tease you with photos encapsulating the miracles of the world.&lt;/p&gt;&lt;p&gt;I have thoroughly enjoyed my tour with my Pixel 2, but I feel I have pushed it to its limits, and I long for more.
I cannot wait to get my hands on a mirrorless camera.
Follow along, and you won&amp;#x27;t be disappointed.
As always, thank you for reading. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Our Most Ambitious DIY Yet]]></title><description><![CDATA[Kiley and I have some BIG news 📰 that we cannot hold in any longer.
We are pregnant! ❤️ We have been sitting on this, anxious to share…]]></description><link>https://codyaprice.com/blog/our-most-ambitious-diy-yet/</link><guid isPermaLink="false">https://codyaprice.com/blog/our-most-ambitious-diy-yet/</guid><pubDate>Sun, 31 May 2020 19:31:35 GMT</pubDate><content:encoded>&lt;p&gt;Kiley and I have some BIG news 📰 that we cannot hold in any longer.
We are pregnant! ❤️&lt;/p&gt;&lt;p&gt;We have been sitting on this, anxious to share since the beginning of April!
In fact, we found out &lt;strong&gt;&lt;em&gt;TWO DAYS&lt;/em&gt;&lt;/strong&gt; before we set out on our adventurous move to Seattle.
We weren&amp;#x27;t planning or expecting a baby, but we feel so incredibly blessed that a healthy baby is growing and cannot wait to meet them!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0017-our-most-ambitious-diy-yet/images/ultrasound.jpg&quot; alt=&quot;Our baby&amp;#x27;s first ultrasound!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Our baby&amp;#x27;s first ultrasound!&lt;/figcaption&gt;&lt;p&gt;Kiley&amp;#x27;s due date is &lt;em&gt;December 10th&lt;/em&gt;.
We find out the gender when we fly back to Kansas City for a week in mid-August.
Kiley wants a girl, but my money is on a boy! &lt;code class=&quot;language-text&quot;&gt;#housedivided&lt;/code&gt; 😤&lt;/p&gt;</content:encoded></item><item><title><![CDATA[We're moving to Seattle, y'all!]]></title><description><![CDATA[I've been teasing this on my socials over the past couple of weeks.
I have accepted an offer at  ngrok , which means that my wife and I are…]]></description><link>https://codyaprice.com/blog/we-re-moving-to-seattle-y-all/</link><guid isPermaLink="false">https://codyaprice.com/blog/we-re-moving-to-seattle-y-all/</guid><pubDate>Tue, 03 Mar 2020 22:42:49 GMT</pubDate><content:encoded>&lt;p&gt;I&amp;#x27;ve been teasing this on my socials over the past couple of weeks.
I have accepted an offer at &lt;a href=&quot;https://ngrok.com/&quot;&gt;ngrok&lt;/a&gt;, which means that my wife and I are moving from Kansas City to Seattle!
My last day at Cerner will be Friday, March 20th, 2020, and I will start as a Software Engineer at ngrok on April 6th, 2020.
I&amp;#x27;m so stoked, y&amp;#x27;all! 🙌&lt;/p&gt;&lt;h2 id=&quot;a-little-reflection&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#a-little-reflection&quot; aria-label=&quot;a little reflection permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A Little Reflection&lt;/h2&gt;&lt;p&gt;It&amp;#x27;s bittersweet, to say the least.
Excluding college, I have lived in Kansas City all of my life.
Hell, I remember going to Bannister Mall and visiting the Toys &amp;#x27;R Us as a wee tike.
Those places exist no more; they are just memories that Cerner&amp;#x27;s Innovations campus now stands on.&lt;/p&gt;&lt;p&gt;If you know me personally, you know that I live and breathe Kansas City.
The Plaza lighting ceremony is nothing short of magical 🧙‍♂️.
I established a relationship with Jesus here.
My wife and I were married here.
We are die-hard First Fridays and Weekend Vintage Revival goers (❤️ &lt;em&gt;Bella Patina&lt;/em&gt;).
I proposed to her under the 12th street bridge in the West Bottoms 💍.
Both of our families are rooted here.
I&amp;#x27;ve met so many kind and considerate, beautiful people here.
I cried when Sporting won the MLS Cup in 2013, when the Royals won the World Series in 2015, and most recently when the Chiefs were crowned Super Bowl LIV champions.
My blood is probably at least thirty-percent Jack Stack beans and the rest an amalgamation of BBQ sauce and Thou Mayest, Blip, and Messenger coffees.
Without a doubt, I will miss all of these &lt;em&gt;lo&lt;strong&gt;KC&lt;/strong&gt;al&lt;/em&gt; gems.
At the same time, I am thrilled about what&amp;#x27;s to come.
Neither my wife nor I have been to the Pacific Northwest before.
We&amp;#x27;ve been assured that it&amp;#x27;s gorgeous.
And we cannot wait to embark on this adventure together!&lt;/p&gt;&lt;h2 id=&quot;regarding-the-local-behemoth&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#regarding-the-local-behemoth&quot; aria-label=&quot;regarding the local behemoth permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Regarding the Local Behemoth&lt;/h2&gt;&lt;p&gt;My work life at Cerner has been nothing short of a blessing.
I have been afforded so many opportunities to grow professionally.
As I&amp;#x27;ve said before, my background was not in web development.
Right from the get-go, I was placed on one of the best teams in the HealtheIntent organization.
I learned JavaScript, React, HTML, CSS, and so many other technical skills throughout my tenure.
It has been a huge stepping stone for my career.&lt;/p&gt;&lt;p&gt;It&amp;#x27;s sad to say goodbye to my current team, and I will miss them immensely.
My manager is incredible, and my teammates are such a joy to work with (even the ones that can be... challenging. You know who you are 😂).
I wish everyone the best going forward and will miss the &lt;em&gt;Fika&lt;/em&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Am I good enough?]]></title><description><![CDATA[opportunities.reject { |person| person.is? :cody } How do you handle rejection? What do you do when something you've been working for and…]]></description><link>https://codyaprice.com/blog/am-i-good-enough/</link><guid isPermaLink="false">https://codyaprice.com/blog/am-i-good-enough/</guid><pubDate>Wed, 12 Feb 2020 23:26:59 GMT</pubDate><content:encoded>&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;opportunities.reject { |person| person.is? :cody }&lt;/code&gt;&lt;/p&gt;&lt;h2 id=&quot;how-do-you-handle-rejection&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#how-do-you-handle-rejection&quot; aria-label=&quot;how do you handle rejection permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How do you handle rejection?&lt;/h2&gt;&lt;p&gt;What do you do when something you&amp;#x27;ve been working for and betting on ends in failure?
How do you react to disappointment and a discouraging result?&lt;/p&gt;&lt;p&gt;I was on the receiving end of one of these situations today.
This was something I had been preparing for and practicing over the past month and a half.
This was an assessment that I did not pass.
Allow me to journal for a moment and pour out my feelings.&lt;/p&gt;&lt;h2 id=&quot;i-mixed-emotions-right-now&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#i-mixed-emotions-right-now&quot; aria-label=&quot;i mixed emotions right now permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;I mixed emotions right now&lt;/h2&gt;&lt;p&gt;To be honest, each of these competing emotions is fighting for the spotlight.
At any given second, one wins out.&lt;/p&gt;&lt;p&gt;On the one hand, I want to sulk.
I want to be sad and recognize my sadness.
I want to be heard and understood by how I feel.
I want to meditate on why I was not good enough.
I feel like an imposter.
&lt;em&gt;Am I good enough?&lt;/em&gt;
Are &lt;strong&gt;&lt;em&gt;they&lt;/em&gt;&lt;/strong&gt; right?&lt;/p&gt;&lt;p&gt;On the other, I am finding that fire burns within me.
I know that I am good enough to pursue my passions.
I know that I am beautifully and intelligently made with purpose and perfect intent.
There is a time and a place for everything.&lt;/p&gt;&lt;h2 id=&quot;i-cannot-dwell&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#i-cannot-dwell&quot; aria-label=&quot;i cannot dwell permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;I cannot dwell&lt;/h2&gt;&lt;p&gt;I know the path forward, but I need to be patient.
My self-worth is not a function of what has happened.
The process takes time.
I&amp;#x27;m going to take the night for introspection, but I cannot help but see this situation as a gift and an opportunity.
I have my faults and my weaknesses, but they will not hold me back.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;But he said to me, &amp;quot;My grace is enough for you, for my power is made perfect in weakness.&amp;quot;
So then, I will boast most gladly about my weaknesses, so that the power of Christ may reside in me.&lt;/p&gt;&lt;p&gt;2 Corinthians 9 (NET)&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So yes, I &lt;strong&gt;&lt;em&gt;am&lt;/em&gt;&lt;/strong&gt; good enough.
And I will be back.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Big O(no) ...tation]]></title><description><![CDATA[I felt inspired because of  this twitter thread  to make a dedicated post on Big O notation and what it means for runtime and space…]]></description><link>https://codyaprice.com/blog/big-o-no-tation/</link><guid isPermaLink="false">https://codyaprice.com/blog/big-o-no-tation/</guid><pubDate>Wed, 22 Jan 2020 00:21:14 GMT</pubDate><content:encoded>&lt;p&gt;I felt inspired because of &lt;a href=&quot;https://twitter.com/devcprice/status/1218468406934016001&quot;&gt;this twitter thread&lt;/a&gt; to make a dedicated post on Big O notation and what it means for runtime and space complexity.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; Big O notation, the &lt;em&gt;&amp;quot;easy&amp;quot;&lt;/em&gt; way: Big O describes how things scale by their inputs, for both &lt;code class=&quot;language-text&quot;&gt;time&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;space&lt;/code&gt; complexity.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Commit this to memory: it only depends on your inputs.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It&amp;#x27;s dealing with &lt;em&gt;growth&lt;/em&gt;.
Just because a function is &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt; doesn&amp;#x27;t necessarily mean that it&amp;#x27;s &lt;em&gt;slower&lt;/em&gt; than &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;.
All that it means is that &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt; &lt;em&gt;&lt;strong&gt;grows much faster&lt;/strong&gt; than &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;&lt;p&gt;As a consequence, Big O allows us to compare the &lt;strong&gt;scalability&lt;/strong&gt; algorithms, even if they&amp;#x27;re completely different!&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;technically-speaking-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#technically-speaking-&quot; aria-label=&quot;technically speaking  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Technically speaking 🗣&lt;/h2&gt;&lt;p&gt;So, technically speaking, the above introduction and TLDR is &lt;em&gt;mostly true&lt;/em&gt;.
The &lt;em&gt;academic&lt;/em&gt; definition of Big O is an &lt;em&gt;upward bound&lt;/em&gt; on growth.
That means that a constant runtime algorithm is also both Big O linear and Big O quadratic.
There also exists a lower bound, called Big Omega, labeled Ω, as well as the combination of O and Ω, Big Theta, or Θ.
But, let&amp;#x27;s not get caught up in the academic details.
In practice and industry, when we say Big O, we mean the &lt;em&gt;lowest&lt;/em&gt; upper bound.
So, if an algorithm is linear, we don&amp;#x27;t say that it&amp;#x27;s exponential because that&amp;#x27;s silly!
If you want to dig more into the nerdy bits, there&amp;#x27;s a &lt;a href=&quot;https://en.wikipedia.org/wiki/Big_O_notation&quot;&gt;wiki article on it&lt;/a&gt; (but you don&amp;#x27;t need to 🙈).&lt;/p&gt;&lt;h2 id=&quot;space-vs-time-complexity&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#space-vs-time-complexity&quot; aria-label=&quot;space vs time complexity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Space vs. Time Complexity&lt;/h2&gt;&lt;p&gt;Big O can help describe the growth of both the time and space complexity of an algorithm.
By the &lt;strong&gt;&lt;em&gt;time&lt;/em&gt;&lt;/strong&gt;, I mean the amount of &lt;em&gt;proportional time&lt;/em&gt; it takes to run the algorithm given the input.
This can also be interpreted as the number of &lt;strong&gt;operations&lt;/strong&gt; given the size of the input.
By &lt;strong&gt;&lt;em&gt;space&lt;/em&gt;&lt;/strong&gt;, I mean the extra space needed to hold stateful information to perform the algorithm given the input.
Depending on the circumstances and constraints of the algorithm, you can sometimes tradeoff time for space and vice versa.
This is a common approach in many algorithms, especially in dynamic programming, which I&amp;#x27;ll have a new blog post on soon!&lt;/p&gt;&lt;p&gt;The most common Big O orders of algorithms that you will find, in orders of growth rate from low to high, are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;constant: &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;logarithmic: &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;linear: &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;linearithmic: &lt;code class=&quot;language-text&quot;&gt;O(n * log n)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;quadratic: &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;exponential: &lt;code class=&quot;language-text&quot;&gt;O(2ⁿ)&lt;/code&gt;&lt;/li&gt;&lt;li&gt;factorial: &lt;code class=&quot;language-text&quot;&gt;O(n!)&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Here&amp;#x27;s a graph of the growth of each of these from Wikipedia.
This shows what each order tends to as they approach larger &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; inputs.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0014-big-o-no-tation/images/comparison_computational_complexity.png&quot; alt=&quot;Graphs of common orders of growth showing the number of operations N versus input size n for each&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Graphs of common orders of growth showing the number of operations N versus input size n for each. &lt;a href=&quot;https://commons.wikimedia.org/w/index.php?curid=50321072&quot;&gt;By Cmglee, CC BY-SA 4.0&lt;/a&gt;&lt;/figcaption&gt;&lt;p&gt;I&amp;#x27;ll be diving into more detail soon on what each of these means, mostly in terms of time complexity below.
But first, let&amp;#x27;s take a look at some comparative &lt;em&gt;runtimes&lt;/em&gt; between all of the above orders.
This picture comes from the &lt;a href=&quot;http://www.algorist.com/&quot;&gt;Algorithm Design Manual, 2nd Edition&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0014-big-o-no-tation/images/algorithm_design_manual_growth_rates.png&quot; alt=&quot;Growth rates of common functions measured in nanoseconds&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Figure 2.4: Growth rates of common functions measured in nanoseconds. (pg. 50)&lt;/figcaption&gt;&lt;p&gt;That picture is incredibly helpful for putting numbers to different common orders of Big O. For a little more context, each operation takes 1 nanosecond.
To get the calculated runtime, you use the &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; on the &lt;code class=&quot;language-text&quot;&gt;y-axis&lt;/code&gt; with the formula on the &lt;code class=&quot;language-text&quot;&gt;x-axis&lt;/code&gt; to calculate the &lt;em&gt;operations&lt;/em&gt;, then multiply by &lt;code class=&quot;language-text&quot;&gt;1 ns&lt;/code&gt; per operation.&lt;/p&gt;&lt;p&gt;Notice that for &lt;code class=&quot;language-text&quot;&gt;n²&lt;/code&gt; and less, you don&amp;#x27;t notice a major difference until &lt;code class=&quot;language-text&quot;&gt;n = 1-10k&lt;/code&gt; items.
But for exponential and factorial growth, it matters real quick!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0014-big-o-no-tation/images/o-n-squared_tweet.png&quot; alt=&quot;Tweet: Bruce Dawson (@BruceDawson0xB) April 22, 2019&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Tweet: &lt;a href=&quot;https://twitter.com/BruceDawson0xB/status/1120381406700429312&quot;&gt;Bruce Dawson (@BruceDawson0xB) April 22, 2019&lt;/a&gt;&lt;/figcaption&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt; is the sweet spot of badly scaling algorithms: fast enough to make it into production, but slow enough to make things fall once it gets there&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Also, notice that at large &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; (10,000+), the &lt;em&gt;size&lt;/em&gt; of larger orders trumps lower ones. &lt;strong&gt;&lt;em&gt;Bigly!&lt;/em&gt;&lt;/strong&gt;
This is why you can drop all terms except the dominant (largest, highest growing) ones when categorizing an algorithm&amp;#x27;s Big O notation!
For example, if you calculate that your algorithm runs at &lt;code class=&quot;language-text&quot;&gt;O(100 + 5n² + 3n)&lt;/code&gt;, we say that it&amp;#x27;s an &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt; algorithm.
Notice that I also dropped off any constants too because they don&amp;#x27;t matter as well!
We classify &lt;code class=&quot;language-text&quot;&gt;O(3n²)&lt;/code&gt; the same as &lt;code class=&quot;language-text&quot;&gt;O(10000n²)&lt;/code&gt; because, at large &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt;, the &lt;code class=&quot;language-text&quot;&gt;n²&lt;/code&gt; will dominate the leading constants.
It also makes the equations simple n&amp;#x27; pretty! 💃&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;common-orders-what-they-mean-with-examples&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#common-orders-what-they-mean-with-examples&quot; aria-label=&quot;common orders what they mean with examples permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Common Orders: What They Mean With Examples&lt;/h2&gt;&lt;p&gt;For now, let&amp;#x27;s focus on &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;.
What kind of algorithms does each of these map to?&lt;/p&gt;&lt;h2 id=&quot;constant-o1&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#constant-o1&quot; aria-label=&quot;constant o1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Constant: O(1)&lt;/h2&gt;&lt;p&gt;Constant time and space complexity: the time/space does not grow with the input.&lt;/p&gt;&lt;h3 id=&quot;time-complexity&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#time-complexity&quot; aria-label=&quot;time complexity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Time Complexity&lt;/h3&gt;&lt;p&gt;Constant time access &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt; is what it takes to access an array element by index, or a hash map by key.
It&amp;#x27;s &lt;strong&gt;constant&lt;/strong&gt;.
In other words, it doesn&amp;#x27;t matter how big the array or hash map gets, those operations are always constant time access.&lt;/p&gt;&lt;h3 id=&quot;space-complexity&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#space-complexity&quot; aria-label=&quot;space complexity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Space Complexity&lt;/h3&gt;&lt;p&gt;If you need to allocate the same amount of things regardless of input in your algorithm, then you have constant space complexity, or &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;.
Notice that just like time complexity, the additional space needed does not grow when the input size grows.
An example of this is holding primitive values as variables in your code, like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; time &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// a string literal, independent of any input&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; count &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// an integer literal, independent of any input&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;linear-on&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#linear-on&quot; aria-label=&quot;linear on permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linear: O(n)&lt;/h2&gt;&lt;h3 id=&quot;time-complexity-1&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#time-complexity-1&quot; aria-label=&quot;time complexity 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Time Complexity&lt;/h3&gt;&lt;p&gt;For &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;, think about an array of items again.
Let&amp;#x27;s say you wanted to print out every element.
What does that mean?
Well, you have to access every element (which happens in constant time &lt;code class=&quot;language-text&quot;&gt;O(1)&lt;/code&gt;), but there are &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; elements in the list, so this is an &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; algorithm.
Stated another way, it takes longer to print out the array when there are more items in the array (and specifically, this is a linear relationship).
For every new item you add to the list, the time to print out the whole list grows by one.
This is also the best conceivable runtime (BCR) for that: you cannot do better than &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; for printing all elements of an array _because you have to touch all &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; items in the list.&lt;/p&gt;&lt;h3 id=&quot;space-complexity-1&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#space-complexity-1&quot; aria-label=&quot;space complexity 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Space Complexity&lt;/h3&gt;&lt;p&gt;Say you want to write an algorithm that reverses the order of a list using a stack, which is a first in, last out list.
This could look something like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;reverseList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; stack &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Stack&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; stack&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; reversedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;stack&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    reversedList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stack&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; reversedList&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The stack used grows proportional to the size of the given input list.
It grows linearly with the input list size, so we use an extra &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; space!
What&amp;#x27;s the runtime of this algorithm? &lt;sup id=&quot;fnref-1&quot;&gt;&lt;a href=&quot;#fn-1&quot; class=&quot;footnote-ref&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&lt;h2 id=&quot;quadratic-on²&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#quadratic-on%C2%B2&quot; aria-label=&quot;quadratic on² permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Quadratic: O(n²)&lt;/h2&gt;&lt;p&gt;How about &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;?&lt;/p&gt;&lt;h3 id=&quot;time-complexity-2&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#time-complexity-2&quot; aria-label=&quot;time complexity 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Time Complexity&lt;/h3&gt;&lt;p&gt;Well, let&amp;#x27;s say you want to print out every element of a &lt;code class=&quot;language-text&quot;&gt;2D array&lt;/code&gt; (or &lt;code class=&quot;language-text&quot;&gt;grid&lt;/code&gt;).
The &lt;code class=&quot;language-text&quot;&gt;grid&lt;/code&gt; is sized at &lt;code class=&quot;language-text&quot;&gt;M x N&lt;/code&gt; (&lt;code class=&quot;language-text&quot;&gt;rows&lt;/code&gt; x &lt;code class=&quot;language-text&quot;&gt;columns&lt;/code&gt;).
So, this operates just like a single array sized &lt;code class=&quot;language-text&quot;&gt;M&lt;/code&gt;, but now you have to print out &lt;code class=&quot;language-text&quot;&gt;N&lt;/code&gt; of them!
So, the generic runtime of printing out a &lt;code class=&quot;language-text&quot;&gt;2D grid&lt;/code&gt; is &lt;code class=&quot;language-text&quot;&gt;O(M * N)&lt;/code&gt;, but if &lt;code class=&quot;language-text&quot;&gt;M = N&lt;/code&gt; (if the &lt;code class=&quot;language-text&quot;&gt;grid&lt;/code&gt; is a square, e.g. &lt;code class=&quot;language-text&quot;&gt;4 x 4&lt;/code&gt;), then you have &lt;code class=&quot;language-text&quot;&gt;N * N == n²&lt;/code&gt;, or &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;.
And again, the BCR here is &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt; because you have to touch every element in the &lt;code class=&quot;language-text&quot;&gt;grid&lt;/code&gt; and there are &lt;code class=&quot;language-text&quot;&gt;N * N&lt;/code&gt; of them.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s try an example!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;doSomeGridWork&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;grid&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; rows&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; rows&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; col &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; col &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; columns&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; col &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; k &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; k &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; k &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;k = &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;k&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;, grid[&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;row&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;col&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;] = &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;grid&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;col&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What&amp;#x27;s the runtime of this code? &lt;sup id=&quot;fnref-2&quot;&gt;&lt;a href=&quot;#fn-2&quot; class=&quot;footnote-ref&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&lt;h3 id=&quot;space-complexity-2&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#space-complexity-2&quot; aria-label=&quot;space complexity 2 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Space Complexity&lt;/h3&gt;&lt;p&gt;Quadratic space complexity is similar to linear space complexity.
If you have an &lt;code class=&quot;language-text&quot;&gt;MxN&lt;/code&gt; &lt;code class=&quot;language-text&quot;&gt;2D grid&lt;/code&gt;, but use something like a &lt;code class=&quot;language-text&quot;&gt;queue&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;stack&lt;/code&gt; to keep track of all unprocessed cells, then you will need to store &lt;code class=&quot;language-text&quot;&gt;O(M * N)&lt;/code&gt; items.
The space required in the storage grows proportional to &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;Let&amp;#x27;s circle back to the other runtimes: &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;O(n * log n)&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;O(2ⁿ)&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;O(n!)&lt;/code&gt;. These are a little more complex but still fairly straightforward.&lt;/p&gt;&lt;h2 id=&quot;logarithmic-olog-n&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#logarithmic-olog-n&quot; aria-label=&quot;logarithmic olog n permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Logarithmic: O(log n)&lt;/h2&gt;&lt;p&gt;Logarithmic growth is very slow-growing, nearly comparable to constant.&lt;/p&gt;&lt;h3 id=&quot;time-complexity-3&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#time-complexity-3&quot; aria-label=&quot;time complexity 3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Time Complexity&lt;/h3&gt;&lt;p&gt;Let&amp;#x27;s say you wanted to find an element in an array.
How long should it take?
Well, it depends.
Are we talking a sorted or unsorted list?&lt;/p&gt;&lt;p&gt;If unsorted, you can&amp;#x27;t tell the order, which means you have to scan the array till you find the item you&amp;#x27;re looking for, if it exists.
So, this is linear &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;.
But, can we do better than that?
Well, not if it&amp;#x27;s unsorted.&lt;/p&gt;&lt;p&gt;However, if we have a sorted list, we can use a binary search, which only takes &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt; time.
Binary search cuts the array in half each time and finds the &lt;code class=&quot;language-text&quot;&gt;middle&lt;/code&gt; element.
If the &lt;code class=&quot;language-text&quot;&gt;middle&lt;/code&gt; is what you&amp;#x27;re searching for, return that &lt;code class=&quot;language-text&quot;&gt;index&lt;/code&gt;.
If what you&amp;#x27;re looking for is less than the &lt;code class=&quot;language-text&quot;&gt;middle&lt;/code&gt;, look in the left half of the sorted list, else look in the right half.
By cutting down the array by half each time, this produces a logarithmic runtime, or &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt;.
It&amp;#x27;s a very slow-growing algorithm which means that it&amp;#x27;s very fast.
You can tell if an item exists in a list of 1 BILLION items within 30 searches.
Crazy!
That&amp;#x27;s 30 vs 1B searches in the worst case!&lt;/p&gt;&lt;h3 id=&quot;space-complexity-3&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#space-complexity-3&quot; aria-label=&quot;space complexity 3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Space Complexity&lt;/h3&gt;&lt;p&gt;For the binary search, you can do it with an iterative approach, like so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchIterative&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;sortedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; key&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; start &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; end &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sortedList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;start &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; end&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;floor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;start &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;end &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sortedList&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      start &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sortedList&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      end &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; middle&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This runs in logarithmic time, but has constant space complexity.
You can also use &lt;em&gt;recursion&lt;/em&gt; to perform binary search:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;sortedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; end&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;sortedList &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;sortedList&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; end &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;floor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;start &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;end &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;key &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; sortedList&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; middle&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;key &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; sortedList&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;middle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sortedList&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; start&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;binarySearchRecursive&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sortedList&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; middle &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; end&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This also runs in logarithmic time.
However, when it comes to space complexity, this is &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt;, can you tell why? &lt;sup id=&quot;fnref-3&quot;&gt;&lt;a href=&quot;#fn-3&quot; class=&quot;footnote-ref&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&lt;h2 id=&quot;linearithmic-on--log-n&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#linearithmic-on--log-n&quot; aria-label=&quot;linearithmic on  log n permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linearithmic: O(n * log n)&lt;/h2&gt;&lt;p&gt;This comes into play mostly with sorting: e.g. merge sort and quicksort.
Both of these operate on &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; items in a list (hence the first &lt;code class=&quot;language-text&quot;&gt;n&lt;/code&gt; term in &lt;code class=&quot;language-text&quot;&gt;n * log n&lt;/code&gt;).
But, what about the &lt;code class=&quot;language-text&quot;&gt;log n&lt;/code&gt; term?
Well, that comes into play by borrowing the &lt;em&gt;cut the array in half method&lt;/em&gt; from binary search.
Take merge sort, for example.
You keep dividing the array down until you have sorted subsections, which takes &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt; time for &lt;code class=&quot;language-text&quot;&gt;log n&lt;/code&gt; sections, followed by merging them back together in &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; time.&lt;/p&gt;&lt;h2 id=&quot;exponential-o2ⁿ&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#exponential-o2%E2%81%BF&quot; aria-label=&quot;exponential o2ⁿ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exponential: O(2ⁿ)&lt;/h2&gt;&lt;p&gt;Exponential growth is very easy to get caught in when using recursion if you ain&amp;#x27;t careful, especially with binary trees.
The inverse of &lt;code class=&quot;language-text&quot;&gt;O(log n)&lt;/code&gt;.
This will make more sense when you get into binary trees, but if you keep doubling your size as N increases, you grow very fast.
Think about the powers of two and how fast they grow (doubling):&lt;/p&gt;&lt;ul&gt;&lt;li&gt;2⁰ = 1&lt;/li&gt;&lt;li&gt;2¹ = 2&lt;/li&gt;&lt;li&gt;2² = 4&lt;/li&gt;&lt;li&gt;2³ = 8&lt;/li&gt;&lt;li&gt;2⁸ = 256&lt;/li&gt;&lt;li&gt;2¹⁰ = 1024&lt;/li&gt;&lt;li&gt;2²⁰ = 1 million&lt;/li&gt;&lt;li&gt;2³⁰ = 1 billion&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Notice the exponent cleanly matches with the number of times you need to search in binary search!&lt;/p&gt;&lt;h2 id=&quot;factorial-on&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#factorial-on&quot; aria-label=&quot;factorial on permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Factorial: O(n!)&lt;/h2&gt;&lt;p&gt;This is kind of hard to achieve, honestly...
But it grows super freakin&amp;#x27; quick and is ultra mega double-plus bad!
Looking back at the table at the start of this post, at &lt;code class=&quot;language-text&quot;&gt;n = 20&lt;/code&gt;, it takes 77.1 years to calculate 😳🤯!&lt;/p&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In practice, algorithmic &lt;code class=&quot;language-text&quot;&gt;time&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;space&lt;/code&gt; complexity follows common patterns that I have outlined in this post.
Big O notation is simply a way to describe them in a way that is independent of environmental or system factors.
I hope this has been helpful!
Please comment below if you have any thoughts or questions and be sure to share on your favorite social media too!
Thanks for reading! 👋&lt;/p&gt;&lt;p&gt;  The runtime of this algorithm is linear, &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;.
While we &lt;em&gt;do&lt;/em&gt; loop &lt;code class=&quot;language-text&quot;&gt;list.length&lt;/code&gt; times twice, remember to drop the leading constant!
As in: &lt;code class=&quot;language-text&quot;&gt;2*O(n)&lt;/code&gt; becomes &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;  If you said &lt;code class=&quot;language-text&quot;&gt;O(n³)&lt;/code&gt;, then you are...incorrect!
The answer is: &lt;code class=&quot;language-text&quot;&gt;O(n²)&lt;/code&gt;!
&lt;strong&gt;&lt;em&gt;How&amp;#x27;s that so?!&lt;/em&gt;&lt;/strong&gt;
Remember what I said at the beginning of this post?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;[Big O] only depends on your inputs&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;  The inner-most &lt;code class=&quot;language-text&quot;&gt;for loop&lt;/code&gt; runs the &lt;em&gt;same number of times &lt;strong&gt;independent of the input&lt;/strong&gt;&lt;/em&gt;.
In our case, it will always run 100000 times.
So, you can think of that as one incredibly slow operation that always runs the same number of times, even if rows and columns are small!
This one is a tricky lil&amp;#x27; curveball for sure! ⚾️&lt;/p&gt;&lt;p&gt;  The recursive binary search algorithm has &lt;strong&gt;&lt;em&gt;logarithmic space complexity&lt;/em&gt;&lt;/strong&gt; because it uses recursion.
With recursion, you get a &amp;quot;free&amp;quot; stack, the calling stack, which is used on each function call.
Since the algorithm calls itself at most &lt;code class=&quot;language-text&quot;&gt;log n&lt;/code&gt; times, the stack will have at most &lt;code class=&quot;language-text&quot;&gt;log n&lt;/code&gt; entries on it.
This space usage doesn&amp;#x27;t come for free, so you have to be aware of it and account for it!
If you recurse too much, you can cause a stack overflow!&lt;/p&gt;&lt;div class=&quot;footnotes&quot;&gt;&lt;hr/&gt;&lt;ol&gt;&lt;li id=&quot;fn-1&quot;&gt;&lt;a href=&quot;#fnref-1&quot; class=&quot;footnote-backref&quot;&gt;↩&lt;/a&gt;&lt;/li&gt;&lt;li id=&quot;fn-2&quot;&gt;&lt;a href=&quot;#fnref-2&quot; class=&quot;footnote-backref&quot;&gt;↩&lt;/a&gt;&lt;/li&gt;&lt;li id=&quot;fn-3&quot;&gt;&lt;a href=&quot;#fnref-3&quot; class=&quot;footnote-backref&quot;&gt;↩&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Plans for my site and content going forward]]></title><description><![CDATA[And no, this ain't a 'going away' post, y'all.
I just wanted to provide an update on where I want to take this site within the foreseeable…]]></description><link>https://codyaprice.com/blog/plans-for-my-site-and-content-going-forward/</link><guid isPermaLink="false">https://codyaprice.com/blog/plans-for-my-site-and-content-going-forward/</guid><pubDate>Sat, 18 Jan 2020 15:27:20 GMT</pubDate><content:encoded>&lt;p&gt;And no, this ain&amp;#x27;t a &amp;#x27;going away&amp;#x27; post, y&amp;#x27;all.
I just wanted to provide an update on where I want to take this site within the foreseeable future.&lt;/p&gt;&lt;h2 id=&quot;index-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#index-&quot; aria-label=&quot;index  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Index /&lt;/h2&gt;&lt;p&gt;For the homepage of my site, I would like to do something new, rather than just a slightly different &lt;code class=&quot;language-text&quot;&gt;/blog&lt;/code&gt;.
The layout of this site is a derivative of the &lt;a href=&quot;https://github.com/gatsbyjs/gatsby-starter-blog&quot;&gt;gatsby starter blog template&lt;/a&gt;.
I have deviated from it over time, but I just haven&amp;#x27;t put in the time to design something better and customized to what I want.
Ideally, it would just highlight the latest content, whether a blog post or a project with a short snippet of my &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt; page.
This leads me to my next plan...&lt;/p&gt;&lt;h2 id=&quot;instagram&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#instagram&quot; aria-label=&quot;instagram permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Instagram&lt;/h2&gt;&lt;p&gt;If you&amp;#x27;re new here or unaware, I have a lot of &lt;em&gt;physical&lt;/em&gt; side projects (e.g. fixing up my house) in flight and I post updates on my &lt;a href=&quot;https://www.instagram.com/lokcal_styles/&quot;&gt;Instagram&lt;/a&gt;.
I want to transition away from using Instagram as my content hosting platform for multiple reasons.
It all boils down to being able to own my content.&lt;/p&gt;&lt;p&gt;In addition to hosting it myself, I want to be able to tell a story or describe what&amp;#x27;s going on in my mini-albums.
I say mini-albums because instead of posting lots of individual photos, I like to group them under one post, like &lt;a href=&quot;https://www.instagram.com/p/B1U7qSxpNfC/?utm_source=ig_web_copy_link&quot;&gt;this one&lt;/a&gt;.
The problem is, Instagram limits you to a maximum of 10 photos/videos per post.
This leads me to a common scenario of having to pick the best 10 of &lt;em&gt;many&lt;/em&gt; photos.
It can be difficult to do this, especially when I want to show some context or scene that cannot be encapsulated within 10 items.
Also, I want to be able to caption individual photos.&lt;/p&gt;&lt;p&gt;Will this hurt my discoverability?
Sure.
But, I doubt I&amp;#x27;m getting &lt;em&gt;that many impressions&lt;/em&gt; from Instagram hashtags.
Who knows, maybe I&amp;#x27;ll just crosspost for a while and link directly to my site&amp;#x27;s posts.&lt;/p&gt;&lt;p&gt;Going forward, when I get around to building the infrastructure and UI, I will be hosting this content under &lt;a href=&quot;https://codyaprice.com/projects/&quot;&gt;/projects&lt;/a&gt;.
Or maybe I&amp;#x27;ll separate out physical projects from digital ones...
Who knows!
I&amp;#x27;ll be a good engineer and iterate on it, but also be sure to provide updates as things change.&lt;/p&gt;&lt;h2 id=&quot;blog-backlog&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#blog-backlog&quot; aria-label=&quot;blog backlog permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Blog Backlog&lt;/h2&gt;&lt;p&gt;Up until now, I have been using the mobile and desktop note-taking app &lt;a href=&quot;https://bear.app/&quot;&gt;Bear&lt;/a&gt; to keep track of my blog post backlog.
While it&amp;#x27;s great for taking notes, I find it lacking for this purpose.
Sure, I can tag items with &lt;code class=&quot;language-text&quot;&gt;#blog&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;#blogpost&lt;/code&gt;, but as time has gone on, the amount of posts has grown past what the app is made for.&lt;/p&gt;&lt;p&gt;For starters, by default, it sorts based on &lt;em&gt;last touched/edited&lt;/em&gt;.
This is fine for notes (which I still take on the app), but not for blog posts that I want to sort in many ways.
It&amp;#x27;s also difficult to mark posts as &lt;em&gt;&amp;quot;done&amp;quot;&lt;/em&gt;, figure out duplicates, and determine how many things are in my backlog (minor).&lt;/p&gt;&lt;p&gt;So, going forward, I will be using GitHub issues to keep track of my backlog (like a good ol&amp;#x27; JIRA queue).
This will allow me to still use tagging and descriptions, but also expose a pseudo-schedule of what&amp;#x27;s coming up.
And, I will be able to support writing requests this way too (if any of y&amp;#x27;all have any 🤷‍♂️).
It will also be nice to have the schedule/backlog local to the site source too.
Maybe this will hold me accountable as well!&lt;/p&gt;&lt;p&gt;If you want to submit a post request, you can &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/issues/new?milestone=Blog+Post+Backlog&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re curious about what&amp;#x27;s in my blog post backlog, you can find it under this &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/milestone/1&quot;&gt;milestone&lt;/a&gt; and this &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/projects/1&quot;&gt;project&lt;/a&gt;.
I will be migrating from Bear to GitHub over the coming days/weeks/&lt;code class=&quot;language-text&quot;&gt;&amp;lt;insert-timeframe-here&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;h2 id=&quot;the-rest-of-the-site&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-rest-of-the-site&quot; aria-label=&quot;the rest of the site permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The rest of the site&lt;/h2&gt;&lt;p&gt;I still need to finish the other two locations on my site: &lt;code class=&quot;language-text&quot;&gt;/essays&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt;.
Truth be told, I do not know what I will put under &lt;code class=&quot;language-text&quot;&gt;/essays&lt;/code&gt; that will be different than &lt;code class=&quot;language-text&quot;&gt;/blog&lt;/code&gt;.
When I started, I loved and took inspiration from &lt;a href=&quot;https://jrsinclair.com/essays/&quot;&gt;James Sinclair&amp;#x27;s site&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;As for the &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt;, I&amp;#x27;m not sure exactly what I want to put there.
I mean, I &lt;em&gt;do know&lt;/em&gt;, but it&amp;#x27;s kind of like when someone puts you on the spot during an &lt;em&gt;icebreaker&lt;/em&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;So, tell us about yourself!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Mind proceeds to go blank&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Last, but not least, I need to finish out the UI and infra when you click on a &lt;code class=&quot;language-text&quot;&gt;TAG&lt;/code&gt;.&lt;/p&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Stay tuned!
There&amp;#x27;s a lot of things to come.&lt;/p&gt;&lt;p&gt;👋&lt;/p&gt;</content:encoded></item><item><title><![CDATA[someTruthyVar && "A new post on boolean coercion"]]></title><description><![CDATA[Click now  Keep reading to see the beginner's guide to what  computedValue && "One Truthy Boi"  evaluates to! To truthy, or not to truthy…]]></description><link>https://codyaprice.com/blog/sometruthyvar-a-new-post-on-boolean-coercion/</link><guid isPermaLink="false">https://codyaprice.com/blog/sometruthyvar-a-new-post-on-boolean-coercion/</guid><pubDate>Thu, 09 Jan 2020 23:03:56 GMT</pubDate><content:encoded>&lt;p&gt;&lt;del&gt;Click now&lt;/del&gt; Keep reading to see the beginner&amp;#x27;s guide to what &lt;code class=&quot;language-text&quot;&gt;computedValue &amp;amp;&amp;amp; &amp;quot;One Truthy Boi&amp;quot;&lt;/code&gt; evaluates to!&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;to-truthy-or-not-to-truthy&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#to-truthy-or-not-to-truthy&quot; aria-label=&quot;to truthy or not to truthy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;To truthy, or not to truthy?&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s do a little code experiment.
How does the value of &lt;code class=&quot;language-text&quot;&gt;computedValue&lt;/code&gt; affect what the expression &lt;code class=&quot;language-text&quot;&gt;computedValue &amp;amp;&amp;amp; &amp;quot;One Truthy Boi&amp;quot;&lt;/code&gt; evaluates to?
Well, let&amp;#x27;s take a gander in &lt;code class=&quot;language-text&quot;&gt;${insertYourFavoriteJavascriptConsole}&lt;/code&gt; (I&amp;#x27;ll run mine in the Chrome browser console).&lt;/p&gt;&lt;p&gt;When &lt;code class=&quot;language-text&quot;&gt;computedValue&lt;/code&gt; is &lt;em&gt;truthy&lt;/em&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; computedValue &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; computedValue &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;One Truthy Boi&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &amp;quot;One Truthy Boi&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Versus when &lt;code class=&quot;language-text&quot;&gt;computedValue&lt;/code&gt; is &lt;em&gt;falsey&lt;/em&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; computedValue &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; computedValue &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;One Truthy Boi&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// false&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And to prove it, a screenshot of it running:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0012-sometruthyvar-a-new-post-on-boolean-coercion/images/console-output.png&quot; alt=&quot;Console output of running the above code snippets.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Console output of running the above code snippets.&lt;/figcaption&gt;&lt;p&gt;Strange.
So, &lt;code class=&quot;language-text&quot;&gt;result&lt;/code&gt; will either be &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;&amp;quot;One Truthy Boi&amp;quot;&lt;/code&gt; depending on what the left-hand-side of the &lt;code class=&quot;language-text&quot;&gt;&amp;amp;&amp;amp;&lt;/code&gt; boolean operation evaluates to.
Interesting... 🤔&lt;/p&gt;&lt;h2 id=&quot;why-this-is-weird-to-me&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#why-this-is-weird-to-me&quot; aria-label=&quot;why this is weird to me permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why this is weird to me&lt;/h2&gt;&lt;p&gt;It turns out this is a pretty standard feature in dynamic languages like JavaScript, Ruby, and Python.
However, if you&amp;#x27;re coming from the land of types, this is... odd.
To understand why let&amp;#x27;s take a look at a little history...&lt;/p&gt;&lt;p&gt;Normally, when performing &lt;code class=&quot;language-text&quot;&gt;(left expression &amp;amp;&amp;amp; right expression)&lt;/code&gt;, you&amp;#x27;re checking for a &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; evaluation, like in a conditional expression for an &lt;code class=&quot;language-text&quot;&gt;if/else&lt;/code&gt; block.
This is called a &lt;em&gt;boolean expression&lt;/em&gt; and evaluates to either &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; OR &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; (two values only; one or the other, not both).&lt;/p&gt;&lt;p&gt;In the &lt;del&gt;ancient manuscripts&lt;/del&gt; &lt;code class=&quot;language-text&quot;&gt;C&lt;/code&gt; language, boolean primitives weren&amp;#x27;t a thing until &lt;code class=&quot;language-text&quot;&gt;C99&lt;/code&gt;.
By that I mean you couldn&amp;#x27;t assign a type of &lt;code class=&quot;language-text&quot;&gt;bool_t&lt;/code&gt; to a variable before &lt;code class=&quot;language-text&quot;&gt;C99&lt;/code&gt;.
Before the boolean types were added, &lt;em&gt;other things&lt;/em&gt; &lt;strong&gt;&lt;em&gt;acted as&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;.
Instead, boolean operations were done on integers, where &lt;code class=&quot;language-text&quot;&gt;0&lt;/code&gt; is &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; and &lt;em&gt;any other number&lt;/em&gt; is &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Similarly, in dynamically-typed languages, many things can act as &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;, even though they aren&amp;#x27;t &lt;strong&gt;&lt;em&gt;literally&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; primitive values.
The expression &lt;code class=&quot;language-text&quot;&gt;true &amp;amp;&amp;amp; &amp;quot;not a boolean&amp;quot;&lt;/code&gt; works in dynamically-typed languages because &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; is, well, &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;&amp;quot;not a boolean&amp;quot;&lt;/code&gt; is &lt;strong&gt;&lt;em&gt;truthy&lt;/em&gt;&lt;/strong&gt;.
And by truthy, I mean that it ain&amp;#x27;t an empty string &lt;code class=&quot;language-text&quot;&gt;&amp;quot;&amp;quot;&lt;/code&gt;!&lt;/p&gt;&lt;p&gt;A few more examples of...&lt;/p&gt;&lt;p&gt;Truthy things:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;non-empty arrays (in JavaScript)&lt;/li&gt;&lt;li&gt;non-empty strings (in JavaScript)&lt;/li&gt;&lt;li&gt;anything non-&lt;code class=&quot;language-text&quot;&gt;nil&lt;/code&gt; in Ruby, including 0! 😳&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Falsey things:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Empty strings (in JavaScript)&lt;/li&gt;&lt;li&gt;Empty arrays (in JavaScript)&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;nil&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;null&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;undefined&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;But here&amp;#x27;s the kicker: in &lt;code class=&quot;language-text&quot;&gt;C&lt;/code&gt;, boolean expressions are &lt;em&gt;just that&lt;/em&gt;: boolean, one of two values.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0012-sometruthyvar-a-new-post-on-boolean-coercion/images/boolean.png&quot; alt=&quot;You can tell that it&amp;#x27;s a boolean because of the way that it is.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;You can tell that it&amp;#x27;s a boolean because of the way that it is.&lt;/figcaption&gt;&lt;p&gt;In other words:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;c&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-c line-numbers&quot;&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;boolean_expression&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// run this code if boolean_expression == TRUE&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// run this code if boolean_expression == FALSE&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But, the astute reader will notice that, for the typical dynamically-typed language, our boolean expressions evaluate to... anything! (Kind of...)&lt;/p&gt;&lt;h2 id=&quot;whats-going-on-here&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#whats-going-on-here&quot; aria-label=&quot;whats going on here permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What&amp;#x27;s going on here?&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s look at a quick example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; leftHandSide &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;some value here&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; rightHandSide &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;One Truthy Boi&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; leftHandSide &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; rightHandSide&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// result = &amp;quot;One Truthy Boi&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this case, the dynamically-typed runtime is &lt;em&gt;coercing&lt;/em&gt; the left-hand side of the boolean expression into a boolean value, like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; leftHandSide &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;some value here&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; rightHandSide &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;One Truthy Boi&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Boolean&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;leftHandSide&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; rightHandSide&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is &lt;em&gt;mostly true&lt;/em&gt;, but we&amp;#x27;ll clarify how it &lt;em&gt;actually works&lt;/em&gt; next.
The main thing to take away is that if the &lt;code class=&quot;language-text&quot;&gt;leftHandSide&lt;/code&gt; expression evaluates to &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;, then &lt;strong&gt;&lt;em&gt;a falsey value is returned&lt;/em&gt;&lt;/strong&gt;.
Let&amp;#x27;s take a deeper look.&lt;/p&gt;&lt;p&gt;So far, we&amp;#x27;ve only looked at &lt;code class=&quot;language-text&quot;&gt;&amp;amp;&amp;amp;&lt;/code&gt; (AND), but there&amp;#x27;s also &lt;code class=&quot;language-text&quot;&gt;||&lt;/code&gt; (OR) and &lt;code class=&quot;language-text&quot;&gt;!&lt;/code&gt; (NOT).
According to &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Description&quot;&gt;MDN on logical operators&lt;/a&gt;, each of these behaves like the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Logical &lt;strong&gt;AND&lt;/strong&gt;: &lt;code class=&quot;language-text&quot;&gt;expr1 &amp;amp;&amp;amp; expr2&lt;/code&gt;&lt;ul&gt;&lt;li&gt;If &lt;code class=&quot;language-text&quot;&gt;expr1&lt;/code&gt; can be converted to &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;, returns &lt;code class=&quot;language-text&quot;&gt;expr2&lt;/code&gt;; else, returns &lt;code class=&quot;language-text&quot;&gt;expr1&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Logical &lt;strong&gt;OR&lt;/strong&gt;: &lt;code class=&quot;language-text&quot;&gt;expr1 || expr2&lt;/code&gt;&lt;ul&gt;&lt;li&gt;If &lt;code class=&quot;language-text&quot;&gt;expr1&lt;/code&gt; can be converted to &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;, returns &lt;code class=&quot;language-text&quot;&gt;expr1&lt;/code&gt;; else, returns &lt;code class=&quot;language-text&quot;&gt;expr2&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Logical &lt;strong&gt;NOT&lt;/strong&gt;: &lt;code class=&quot;language-text&quot;&gt;!expr&lt;/code&gt;&lt;ul&gt;&lt;li&gt;Returns &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; if it can be converted to &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;; else, returns &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Take my word for it, but Ruby &lt;a href=&quot;http://ruby-doc.com/docs/ProgrammingRuby/html/tut_expressions.html#UF&quot;&gt;boolean expression&lt;/a&gt; behave pretty much identically.&lt;/p&gt;&lt;p&gt;So, &lt;em&gt;did you catch it&lt;/em&gt;?&lt;/p&gt;&lt;p&gt;There&amp;#x27;s a &lt;strong&gt;big&lt;/strong&gt; difference in what I, coming from a strongly typed background, would expect versus what the actual boolean operation defines:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In the case where the expression &lt;em&gt;short-circuit evaluates&lt;/em&gt;, instead of returning a &lt;strong&gt;boolean literal&lt;/strong&gt; (i.e. &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;), it returns the value that forced the short-circuit path, e.g. &lt;code class=&quot;language-text&quot;&gt;undefined &amp;amp;&amp;amp; true&lt;/code&gt; returns &lt;code class=&quot;language-text&quot;&gt;undefined&lt;/code&gt; instead of &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;This is why in the original example we saw&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;computedValue &amp;amp;&amp;amp; &amp;quot;One Truthy Boi&amp;quot;&lt;/code&gt; &lt;strong&gt;&lt;em&gt;return either&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; &lt;strong&gt;&lt;em&gt;or&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;&amp;quot;One Truthy Boi&amp;quot;&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;This is also why, in &lt;a href=&quot;https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logical--operator&quot;&gt;React&lt;/a&gt;, you can short circuit return jsx like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Example&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;showGreeting&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setShowGreeting&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setShowGreeting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;showGreeting&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;showGreeting &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Hide greeting&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Show greeting&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;showGreeting &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Hello there! 👋&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;There&amp;#x27;s an immense amount of flexibility gained from operating as dynamically-typed languages do.
Often though, it can produce surprising results if you&amp;#x27;re not careful.
Usually, it works out well, but there are cases where short-circuit evaluation of boolean expressions (logical operators) can produce unexpected results.&lt;/p&gt;&lt;p&gt;I&amp;#x27;ll leave you with an example.
Take for instance the following React code.
What do you think happens when &lt;code class=&quot;language-text&quot;&gt;list.length === 0&lt;/code&gt;?
Have a look for yourself below 👀:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Example&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setList&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;addItem&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;clearList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;List length: &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;addItem&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        Add One
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;clearList&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        Clear List
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div caption=&quot;An interactive example with the ability to change the list&quot;&gt;&lt;style data-emotion-css=&quot;1cuoivm&quot;&gt;.css-1cuoivm{margin:0 auto;text-align:center;}&lt;/style&gt;&lt;div class=&quot;css-1cuoivm&quot;&gt;&lt;p&gt;List length: 0&lt;/p&gt;&lt;div&gt;&lt;button type=&quot;button&quot;&gt;Add One&lt;/button&gt;&lt;button type=&quot;button&quot;&gt;Clear List&lt;/button&gt;&lt;/div&gt;0&lt;/div&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Planning to fail]]></title><description><![CDATA[Planning may be valuable, but the plan is worthless the moment it is created. Ah, here we are again. 😏
New year, new... quarter.
New…]]></description><link>https://codyaprice.com/blog/planning-to-fail/</link><guid isPermaLink="false">https://codyaprice.com/blog/planning-to-fail/</guid><pubDate>Tue, 07 Jan 2020 18:43:26 GMT</pubDate><content:encoded>&lt;blockquote&gt;&lt;p&gt;Planning may be valuable, but the plan is worthless the moment it is created.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr/&gt;&lt;p&gt;Ah, here we are again. 😏
New year, new... quarter.
New quarter, new... planning cycle.
New planning cycle, &lt;del&gt;new...&lt;/del&gt; same old, archaic process to appease the &lt;del&gt;gods&lt;/del&gt; management.&lt;/p&gt;&lt;p&gt;From my perspective, as a developer, four things bother me about quarterly planning, &lt;em&gt;especially so in &lt;strong&gt;E N T E R P R I S E&lt;/strong&gt;&lt;/em&gt;:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Big Room Planning, aka BRP&lt;/li&gt;&lt;li&gt;Plans are consistent&lt;/li&gt;&lt;li&gt;&lt;em&gt;The weeds&lt;/em&gt; 🌿&lt;/li&gt;&lt;li&gt;The 70% mark&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This &lt;a href=&quot;https://productcoalition.com/the-major-problems-with-safe-1e797f7e48f8&quot;&gt;article&lt;/a&gt; perfectly sums up my main issues with scaled &lt;em&gt;&amp;quot;agile&amp;quot;&lt;/em&gt; planning, but I want to focus on my experience.
I&amp;#x27;ll air my grievances below. 👇&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;please-dont-brp-at-the-table-its-impolite&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#please-dont-brp-at-the-table-its-impolite&quot; aria-label=&quot;please dont brp at the table its impolite permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Please don&amp;#x27;t BRP at the table, it&amp;#x27;s impolite!&lt;/h2&gt;&lt;p&gt;So, big room planning.
It&amp;#x27;s this &lt;strong&gt;&lt;em&gt;&amp;quot;wonderful&amp;quot;&lt;/em&gt;&lt;/strong&gt; two days at the beginning of each quarter where the entire organization crams into auditoriums and meeting rooms to &lt;del&gt;fight to the death&lt;/del&gt; plan for and commit to client requests.
At a glance, it sounds great.&lt;/p&gt;&lt;p&gt;&lt;em&gt;The problem is, it&amp;#x27;s chock full of rigid processes, structure, and bureaucracy.&lt;/em&gt;&lt;/p&gt;&lt;p&gt;We plan because planning is valuable.
Without a planning phase, we wouldn&amp;#x27;t be able to meet the business needs, opportunities, and priorities of our clients.&lt;/p&gt;&lt;p&gt;However!&lt;/p&gt;&lt;p&gt;&lt;em&gt;The plan.&lt;/em&gt; The one that is &lt;strong&gt;&lt;em&gt;committed&lt;/em&gt;&lt;/strong&gt; to should be thrown out as soon as you create it.
Maybe that&amp;#x27;s a bit harsh.
At the very least, it should &lt;strong&gt;not&lt;/strong&gt; be as rigid as it is.&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s the thing: as time goes on (as it tends to do 💅), priorities shift, things come up, and requirements change.
&lt;em&gt;Maybe your client decided they don&amp;#x27;t want a racecar?&lt;/em&gt;&lt;/p&gt;&lt;p&gt;What&amp;#x27;s dope is that through agile development practices, you can meet their new needs, requirements, and/or problems head-on as opposed to being locked in.&lt;/p&gt;&lt;p&gt;The plan is a high-level, coarse-grained, hand-wavy pass that only has a value at the moment of inception.
And that&amp;#x27;s because...&lt;/p&gt;&lt;h2 id=&quot;plans-are-consistently-wrong&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#plans-are-consistently-wrong&quot; aria-label=&quot;plans are consistently wrong permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Plans are consistent(ly wrong)&lt;/h2&gt;&lt;p&gt;Let me paint you a picture. 👨‍🎨&lt;/p&gt;&lt;p&gt;Morning scrum.
The air is thick and uncomfortably familiar.
It&amp;#x27;s halfway through the third sprint of the quarter and your product manager is trying not to overdose on anxiety medication.
You hope they&amp;#x27;re doing alright, but you know their manager is barking at them to corral their &lt;del&gt;resources&lt;/del&gt; engineers.
It&amp;#x27;s nearly your turn in the speaking rotation and you know what&amp;#x27;s coming.
Your neck hair is alert, knees weak, arms heavy 🍝.
As you explain why you&amp;#x27;re four days rolled over from the estimate, your PM lets it out:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&amp;quot;What&amp;#x27;s taking so long on X? Are you blocked by something or someone? &lt;strong&gt;Do I need to log a R I S K&lt;/strong&gt;?&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;To them, &lt;strong&gt;&lt;em&gt;you are behind.&lt;/em&gt;&lt;/strong&gt;
Well, you&amp;#x27;re not behind, but &lt;em&gt;according to the plan&lt;/em&gt; you are.
&lt;em&gt;If only they understood that development ain&amp;#x27;t linear...&lt;/em&gt;&lt;/p&gt;&lt;p&gt;Does that sound familiar?
If not, bless your heart. ❤️&lt;/p&gt;&lt;p&gt;The thing about plans and estimates is that they are consistently wrong about 90% of the time.
I&amp;#x27;ll be honest, I pulled that percentage out of my gut.&lt;/p&gt;&lt;p&gt;The fact of the matter is that you cannot account for what happens in the future, no matter how hard you try.
This is especially true when you have &lt;em&gt;external&lt;/em&gt; dependencies on other teams or, as my manager so eloquently put it, you&amp;#x27;re &lt;em&gt;building the plane as you fly it&lt;/em&gt; ✈️.&lt;/p&gt;&lt;p&gt;Go ahead and pad your estimate with an extra ten, thirty, or fifty percent.
It&amp;#x27;s still wrong.&lt;/p&gt;&lt;p&gt;Go ahead and try to break your task down into pieces as small as possible.
Estimate each of those pieces.
It&amp;#x27;s still wrong.&lt;/p&gt;&lt;p&gt;Don&amp;#x27;t believe me?
That&amp;#x27;s fine.
Let&amp;#x27;s try to estimate the complexity of tasks.&lt;/p&gt;&lt;h2 id=&quot;were-getting-lost-in-the-weeds-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#were-getting-lost-in-the-weeds-&quot; aria-label=&quot;were getting lost in the weeds  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;We&amp;#x27;re getting lost in &lt;em&gt;the weeds&lt;/em&gt; 🌿&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;How can I plan for something if I don&amp;#x27;t know the inner details?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Here&amp;#x27;s a scenario that pretty much played out verbatim this morning (I&amp;#x27;ve anonymized it):&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&amp;quot;Hey, so do you think you can do X?&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Well, that depends on the scope of X.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&amp;quot;Cool. So you can? Do you have any concerns?&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Well, I do have some concerns. I see Y and Z as bottlenecks.
Can we talk through that?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&amp;quot;Hey now, we&amp;#x27;re getting into the weeds, don&amp;#x27;t you think?
Are you confident we can commit to this?&amp;quot;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;For 🤬sake!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;And we wonder why &amp;quot;things come up&amp;quot; or &amp;quot;never go as planned&amp;quot;?
How can I confidently plan for something if I don&amp;#x27;t know the inner details?
No, I&amp;#x27;m not suggesting I know every fine-grained detail.
On the contrary, I just want to know more than just the hand-wavy requirements because, as they say, &lt;strong&gt;&lt;em&gt;the devil is in the details&lt;/em&gt;&lt;/strong&gt; 👿&lt;/p&gt;&lt;p&gt;During planning, we should aim to align ourselves with the intent to design and implement the solutions to the problems the client has &lt;strong&gt;&lt;em&gt;at this time&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;And if the client changes their mind?
Not if, &lt;em&gt;when&lt;/em&gt;.
&lt;em&gt;When&lt;/em&gt; the client changes their mind, adjust because &lt;em&gt;you&amp;#x27;re agile&lt;/em&gt;.&lt;/p&gt;&lt;h2 id=&quot;the-70-mark-or-70-of-the-time-it-fails-every-time&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-70-mark-or-70-of-the-time-it-fails-every-time&quot; aria-label=&quot;the 70 mark or 70 of the time it fails every time permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;The 70% mark&lt;/em&gt;; Or, 70% of the time it fails every time&lt;/h2&gt;&lt;p&gt;In my organization, there&amp;#x27;s a division that produces patient-facing applications.
I used to work directly in this group and one of their mottos during planning was to only commit to 70% of your capacity.&lt;/p&gt;&lt;p&gt;As a developer, your capacity is an imaginary metric that determines how much &lt;em&gt;stuff&lt;/em&gt; you can implement over a given period, generally a quarter.
So, let&amp;#x27;s say you can complete 10 units of work.
You&amp;#x27;re only supposed to commit to 7 units of work because the remaining 3 units, or 30%, are to be allocated to &lt;strong&gt;&lt;em&gt;&amp;quot;the unknown&amp;quot;&lt;/em&gt;&lt;/strong&gt; (which includes PTO, sick days, unforeseen events, etc).&lt;/p&gt;&lt;p&gt;So, we&amp;#x27;re back to padding estimates? 😅&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s my issue with the above &lt;del&gt;rule&lt;/del&gt; &lt;em&gt;suggestion&lt;/em&gt; (and I don&amp;#x27;t mean for this to sound as aggressive and abrasive as it may end up).
So far, management has &lt;em&gt;linearly distributed all 10 units of work throughout the quarter&lt;/em&gt;.
In other words, the first 70% of the quarter is design and implementation and the last 30% of the quarter is &lt;em&gt;free space&lt;/em&gt; for &lt;code class=&quot;language-text&quot;&gt;no-op&lt;/code&gt; &lt;em&gt;stuff&lt;/em&gt;.
This isn&amp;#x27;t explicitly stated anywhere, but it is reflected in the JIRA dashboards and charts that track quarterly progress.&lt;/p&gt;&lt;p&gt;When you&amp;#x27;re &amp;quot;behind&amp;quot; it could be because you took two weeks of PTO at the beginning of the quarter.
Or because you got sick and your JIRA sat in the &amp;quot;in progress&amp;quot; column for two or three days without any development.
Or because last week a production incident brought down critical infrastructure so you had to shift priorities mid-sprint and shelve your in-progress JIRA.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re going to shave off 30% of capacity, you cannot assume it will be equally distributed throughout the quarter.
Also, who are we kidding with this capacity metric? 🤔&lt;/p&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As it stands, I strongly dislike the planning week.
It feels like a waste of time past the initial hour or two of the first day.&lt;/p&gt;&lt;p&gt;Going forward, I would love to approach planning differently.
Luckily, this time we were able to deviate even though we&amp;#x27;re still tied to the bureaucracy and paperwork 🤙.&lt;/p&gt;&lt;p&gt;Instead of the churn and burn, let&amp;#x27;s maintain a priority queue backlog of work.
Planning should be a continuous process, like recurring scrum and retro meetings.
A priority queue is great for this because it&amp;#x27;s not an immutable source of truth.
If a task shifts priority, the queue adjusts accordingly, and thus we do too.
That&amp;#x27;s true agility.&lt;/p&gt;&lt;p&gt;And please, let&amp;#x27;s skip the estimations because they&amp;#x27;re &lt;strong&gt;never correct&lt;/strong&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Cool UI Tricks: Pointer Event Passthrough on my Site's Primary Navigation]]></title><description><![CDATA["You have to be transparent so you no longer  cast a shadow  block clicks but instead let the  light  clicks pass through you" - Kamand…]]></description><link>https://codyaprice.com/blog/cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/</link><guid isPermaLink="false">https://codyaprice.com/blog/cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/</guid><pubDate>Fri, 20 Dec 2019 01:18:49 GMT</pubDate><content:encoded>&lt;blockquote&gt;&lt;p&gt;&amp;quot;You have to be transparent so you no longer &lt;del&gt;cast a shadow&lt;/del&gt; block clicks but instead let the &lt;del&gt;light&lt;/del&gt; clicks pass through you&amp;quot; - Kamand Kojouri...&lt;em&gt;ish&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;hr/&gt;&lt;h2 id=&quot;post-mortem-or-hey-friends-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#post-mortem-or-hey-friends-&quot; aria-label=&quot;post mortem or hey friends  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Post Mortem: Or, Hey Friends 👋&lt;/h2&gt;&lt;p&gt;Look. 👀
I &lt;em&gt;really tried&lt;/em&gt; to keep this article short and sweet.
But, I failed.
It may seem long (because it kinda is 😬), but stick with me!
It&amp;#x27;s worth it, trust me. 🤞&lt;/p&gt;&lt;small&gt;Also, you can skip around if you already know some parts or if you ain&amp;#x27;t interested in the juicy deets. 💅&lt;/small&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/ight-imma-head-out.png&quot; alt=&quot;Ight imma head out. 🧽🚶‍♂️&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Ight imma head out. 🧽🚶‍♂️&lt;/figcaption&gt;&lt;p&gt;Back to the post.&lt;/p&gt;&lt;h2 id=&quot;whats-up-cody&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#whats-up-cody&quot; aria-label=&quot;whats up cody permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What&amp;#x27;s up Cody?&lt;/h2&gt;&lt;p&gt;I recently updated my primary navigation.
You know, this thing:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/primary-navigation.png&quot; alt=&quot;Primary navigation, with minor annotations.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Primary navigation, with minor annotations.&lt;/figcaption&gt;&lt;p&gt;Underneath the primary navigation is a &lt;a href=&quot;https://www.stripe.com&quot;&gt;stripe&lt;/a&gt; inspired header.
Inside the clipped header is a &lt;code class=&quot;language-text&quot;&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; element that renders a starry background that you can interact with through hover and clicking.
Hovering produces a &lt;em&gt;&amp;quot;brightening&amp;quot;&lt;/em&gt; effect on stars adjacent to the mouse, like so:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/navigation-hover.gif&quot; alt=&quot;Navigation mouse hover animation&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Navigation mouse hover animation&lt;/figcaption&gt;&lt;p&gt;And clicking allows you to &lt;em&gt;&amp;quot;blow up&amp;quot;&lt;/em&gt; the stars, blasting them in all directions:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/navigation-click.gif&quot; alt=&quot;Navigation mouse click interaction&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Navigation mouse click interaction&lt;/figcaption&gt;&lt;h2 id=&quot;the-problem&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-problem&quot; aria-label=&quot;the problem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Problem&lt;/h2&gt;&lt;p&gt;The navigation is rather delightful to play with.
Unfortunately, you originally could not click or hover on the region between my name and the navigation links.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/annotated-primary-navigation.png&quot; alt=&quot;Call my navigation Sprint because this was a dead zone, my friend. 🤙&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Call my navigation Sprint because this was a dead zone, my friend. 🤙&lt;/figcaption&gt;&lt;p&gt;Even though there doesn&amp;#x27;t appear to be anything between my name and the list of links, pointer interactions fail to register!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/navigation-blocks-interaction.gif&quot; alt=&quot;The navigation blocks any interactions with the stars! 🙅‍♂️&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;The navigation blocks any interactions with the stars! 🙅‍♂️&lt;/figcaption&gt;&lt;p&gt;Bummer! 😢&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;How do we fix that!? 🧐&lt;/p&gt;&lt;/blockquote&gt;&lt;h2 id=&quot;interactive-example-time-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#interactive-example-time-&quot; aria-label=&quot;interactive example time  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Interactive Example Time ⏰&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s play around with some interactable examples!
In each example, you can click and hover on things within the dashed boxes.
I&amp;#x27;ve created a mock navigation header that loosely resembled the primary navigation on my site.
Think of it like if you turned the graphics settings &lt;strong&gt;&lt;em&gt;way&lt;/em&gt;&lt;/strong&gt; down.&lt;/p&gt;&lt;p&gt;For this first example, I want to demonstrate the way my navigation originally worked; or, what happens when the navigation blocks interaction as if there&amp;#x27;s an invisible wall.&lt;/p&gt;&lt;p&gt;As you click on items, the &lt;em&gt;&amp;quot;Last clicked&amp;quot;&lt;/em&gt; element will update to display what you last clicked on.
You can do the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The background is both &lt;em&gt;clickable&lt;/em&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;em&gt;hoverable&lt;/em&gt;&lt;/li&gt;&lt;li&gt;The avatar circle is both &lt;em&gt;clickable&lt;/em&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;em&gt;hoverable&lt;/em&gt;&lt;/li&gt;&lt;li&gt;The navigation region is &lt;em&gt;clickable&lt;/em&gt;&lt;/li&gt;&lt;li&gt;You can toggle on/off the visibility of the navigation bounds (note: this does not remove them entirely; they are still rendered, but will just be completely transparent or invisible)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;em&gt;Isn&amp;#x27;t it odd that there&amp;#x27;s a central region where an interactivity dead zone exists?&lt;/em&gt;&lt;/p&gt;&lt;div caption=&quot;An interactable example displaying our &amp;quot;invisible wall&amp;quot;&quot;&gt;&lt;style data-emotion-css=&quot;cbkym3&quot;&gt;.css-cbkym3{background-color:#303a52;width:100%;height:10rem;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:relative;}&lt;/style&gt;&lt;div class=&quot;css-cbkym3&quot;&gt;&lt;style data-emotion-css=&quot;1qdi3kc animation-15lk19q&quot;&gt;.css-1qdi3kc{display:block;position:absolute;width:100%;height:100%;border:0;background-color:transparent;background-size:2rem 2rem;}.css-1qdi3kc:hover{background-image:linear-gradient(135deg,rgba(0,0,0,0.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,0.1) 50%,rgba(0,0,0,0.1) 75%,transparent 75%,transparent);color:#fff;-webkit-animation:animation-15lk19q 2.8s linear infinite;animation:animation-15lk19q 2.8s linear infinite;}.css-1qdi3kc:active{backgroundColor:#574b90;}@-webkit-keyframes animation-15lk19q{0%{background-position:0 0;}100%{background-position:2rem 4rem;}}@keyframes animation-15lk19q{0%{background-position:0 0;}100%{background-position:2rem 4rem;}}&lt;/style&gt;&lt;button name=&quot;background&quot; class=&quot;css-1qdi3kc&quot;&gt;&lt;/button&gt;&lt;style data-emotion-css=&quot;1k46j4&quot;&gt;.css-1k46j4{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;background-color:0;padding:1rem;width:100%;position:relative;pointer-cvents:auto;}&lt;/style&gt;&lt;nav id=&quot;navigation-0&quot; class=&quot;css-1k46j4&quot;&gt;&lt;style data-emotion-css=&quot;13wt5e7&quot;&gt;.css-13wt5e7{height:4rem;width:4rem;border-radius:100%;border:0;background-color:#9e579d;box-shadow:0 0.25rem 0.5rem 0 rgba(0,0,0,0.38);pointer-cvents:auto;}.css-13wt5e7:hover{backgroundcolor:#fc85ae;boxshadow:0 0.375rem 0.5rem 0 rgba(0,0,0,0.54);}&lt;/style&gt;&lt;button type=&quot;button&quot; name=&quot;avatar circle&quot; class=&quot;css-13wt5e7&quot;&gt;&lt;/button&gt;&lt;style data-emotion-css=&quot;oby96h&quot;&gt;.css-oby96h{background:0;border-radius:0.25rem;border:0;color:#fff;padding:1rem;pointer-events:auto;}.css-oby96h:hover{background-color:#574b90;}&lt;/style&gt;&lt;button type=&quot;button&quot; name=&quot;the link&quot; class=&quot;css-oby96h&quot;&gt;A Link&lt;/button&gt;&lt;/nav&gt;&lt;/div&gt;&lt;style data-emotion-css=&quot;13o7eu2&quot;&gt;.css-13o7eu2{display:block;}&lt;/style&gt;&lt;label class=&quot;css-13o7eu2&quot;&gt;Show navigation bounds? &lt;input type=&quot;checkbox&quot;/&gt;&lt;/label&gt;&lt;style data-emotion-css=&quot;1uk1gs8&quot;&gt;.css-1uk1gs8{margin:0;}&lt;/style&gt;&lt;p class=&quot;css-1uk1gs8&quot;&gt;Last clicked: nothing&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;what-went-wrong&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#what-went-wrong&quot; aria-label=&quot;what went wrong permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What Went Wrong&lt;/h2&gt;&lt;p&gt;The above behavior is unsurprising if you&amp;#x27;re familiar with DOM flow and stacking contexts.
But, to the average person, it provides a &lt;strong&gt;&lt;em&gt;bad user experience&lt;/em&gt;&lt;/strong&gt; because it breaks the &lt;a href=&quot;https://en.wikipedia.org/wiki/Principle_of_least_astonishment&quot;&gt;Principal of Least Astonishment&lt;/a&gt;.
You would expect the starry background in my primary navigation to be interactable in all of its rendered regions.
It is jarring to experience that &lt;em&gt;&amp;quot;invisible wall&amp;quot;&lt;/em&gt;.
I want to explain more on why this wall exists, but first, here&amp;#x27;s the same example from above, but now you can also toggle on/off the &lt;em&gt;&amp;quot;invisible wall&amp;#x27;s&amp;quot;&lt;/em&gt; &lt;strong&gt;&lt;em&gt;&amp;quot;presence&amp;quot;&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;div caption=&quot;An interactable example with the ability to remove the &amp;quot;invisible wall&amp;quot;&quot;&gt;&lt;style data-emotion-css=&quot;cbkym3&quot;&gt;.css-cbkym3{background-color:#303a52;width:100%;height:10rem;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:relative;}&lt;/style&gt;&lt;div class=&quot;css-cbkym3&quot;&gt;&lt;style data-emotion-css=&quot;1qdi3kc animation-15lk19q&quot;&gt;.css-1qdi3kc{display:block;position:absolute;width:100%;height:100%;border:0;background-color:transparent;background-size:2rem 2rem;}.css-1qdi3kc:hover{background-image:linear-gradient(135deg,rgba(0,0,0,0.1) 25%,transparent 25%,transparent 50%,rgba(0,0,0,0.1) 50%,rgba(0,0,0,0.1) 75%,transparent 75%,transparent);color:#fff;-webkit-animation:animation-15lk19q 2.8s linear infinite;animation:animation-15lk19q 2.8s linear infinite;}.css-1qdi3kc:active{backgroundColor:#574b90;}@-webkit-keyframes animation-15lk19q{0%{background-position:0 0;}100%{background-position:2rem 4rem;}}@keyframes animation-15lk19q{0%{background-position:0 0;}100%{background-position:2rem 4rem;}}&lt;/style&gt;&lt;button name=&quot;background&quot; class=&quot;css-1qdi3kc&quot;&gt;&lt;/button&gt;&lt;style data-emotion-css=&quot;18c13lq&quot;&gt;.css-18c13lq{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;background-color:0;padding:1rem;width:100%;position:relative;pointer-cvents:none;}&lt;/style&gt;&lt;nav id=&quot;navigation-1&quot; class=&quot;css-18c13lq&quot;&gt;&lt;style data-emotion-css=&quot;13wt5e7&quot;&gt;.css-13wt5e7{height:4rem;width:4rem;border-radius:100%;border:0;background-color:#9e579d;box-shadow:0 0.25rem 0.5rem 0 rgba(0,0,0,0.38);pointer-cvents:auto;}.css-13wt5e7:hover{backgroundcolor:#fc85ae;boxshadow:0 0.375rem 0.5rem 0 rgba(0,0,0,0.54);}&lt;/style&gt;&lt;button type=&quot;button&quot; name=&quot;avatar circle&quot; class=&quot;css-13wt5e7&quot;&gt;&lt;/button&gt;&lt;style data-emotion-css=&quot;oby96h&quot;&gt;.css-oby96h{background:0;border-radius:0.25rem;border:0;color:#fff;padding:1rem;pointer-events:auto;}.css-oby96h:hover{background-color:#574b90;}&lt;/style&gt;&lt;button type=&quot;button&quot; name=&quot;the link&quot; class=&quot;css-oby96h&quot;&gt;A Link&lt;/button&gt;&lt;/nav&gt;&lt;/div&gt;&lt;style data-emotion-css=&quot;13o7eu2&quot;&gt;.css-13o7eu2{display:block;}&lt;/style&gt;&lt;label class=&quot;css-13o7eu2&quot;&gt;Show navigation bounds? &lt;input type=&quot;checkbox&quot;/&gt;&lt;/label&gt;&lt;style data-emotion-css=&quot;13o7eu2&quot;&gt;.css-13o7eu2{display:block;}&lt;/style&gt;&lt;label class=&quot;css-13o7eu2&quot;&gt;Remove &lt;em&gt;&amp;quot;invisible wall&amp;quot;&lt;/em&gt;? &lt;input type=&quot;checkbox&quot; checked=&quot;&quot;/&gt;&lt;/label&gt;&lt;style data-emotion-css=&quot;1uk1gs8&quot;&gt;.css-1uk1gs8{margin:0;}&lt;/style&gt;&lt;p class=&quot;css-1uk1gs8&quot;&gt;Last clicked: nothing&lt;/p&gt;&lt;/div&gt;&lt;p&gt;When the navigation bounds are visible, but we remove the &lt;em&gt;&amp;quot;invisible wall&amp;quot;&lt;/em&gt;, the background can receive our click!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/click-passthrough.png&quot; alt=&quot;Still image: The click passes through the navigation region and registers on the background!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Still image: The click passes through the navigation region and registers on the background!&lt;/figcaption&gt;&lt;h2 id=&quot;how-it-works&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#how-it-works&quot; aria-label=&quot;how it works permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How it Works&lt;/h2&gt;&lt;p&gt;TLDR: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events&quot;&gt;pointer-events&lt;/a&gt;!&lt;/p&gt;&lt;p&gt;There is a CSS property called &lt;code class=&quot;language-text&quot;&gt;pointer-events&lt;/code&gt; which allows you to manipulate if a DOM element receives pointer events (e.g. &lt;code class=&quot;language-text&quot;&gt;click&lt;/code&gt;s, &lt;code class=&quot;language-text&quot;&gt;hover&lt;/code&gt;, etc).
If you set it to &lt;code class=&quot;language-text&quot;&gt;none&lt;/code&gt;, then that element and all of its children will no longer process pointer events!&lt;/p&gt;&lt;p&gt;🤯&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s look at the simplified DOM of my navigation with minimal styling using &lt;a href=&quot;https://emotion.sh/docs/introduction&quot;&gt;emotion, an incredible css-in-js library&lt;/a&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* top level element sets pointer events to none */&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; pointerEvents&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;none&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    display&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;flex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    alignItems&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;relative&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* 👈 this is important */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* The starry background 👇*/&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;absolute&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* 👈 this is important */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;canvas&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;✨&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;canvas&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;nav&lt;/span&gt;
      &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        display&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;flex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        justifyContent&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;space-between&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        position&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;relative&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* 👈 this is important */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* manually enable pointerEvents for all children after here */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;#&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; pointerEvents&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;auto&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        Cody A. Price
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          display&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;flex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          listStyle&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          margin&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          pointerEvents&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;auto&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/*
          These will inherit `pointer-events: auto;`
          from the parent &amp;lt;ul&amp;gt; by default
        */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;#&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Blog&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;#&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;About&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;nav&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Notice that we turn off all &lt;code class=&quot;language-text&quot;&gt;pointer-events&lt;/code&gt; on the parent element and then selectively turn &lt;code class=&quot;language-text&quot;&gt;pointer-events&lt;/code&gt; back on for &lt;strong&gt;&lt;em&gt;specific children&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/i-love-all-my-children-equally.gif&quot; alt=&quot;If you&amp;#x27;re saying I play favorites, you&amp;#x27;re wrong. I love all my children equally.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;If you&amp;#x27;re saying I play favorites, you&amp;#x27;re wrong. I love all my children equally.&lt;/figcaption&gt;&lt;h3 id=&quot;unpacking-it-all&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#unpacking-it-all&quot; aria-label=&quot;unpacking it all permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unpacking it All&lt;/h3&gt;&lt;p&gt;There&amp;#x27;s a lot to unpack here, so let&amp;#x27;s get down to business.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/lets-get-down-to-business.gif&quot; alt=&quot;Let&amp;#x27;s get down to business!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Let&amp;#x27;s get down to business!&lt;/figcaption&gt;&lt;p&gt;We need to talk about DOM flow, the box model, positioning, and stacking contexts.
Be warned, I am going to gloss over a lot of the details because these topics deserve a post in themselves.
There&amp;#x27;s a ton of nuance at play, so &lt;strong&gt;&lt;em&gt;readers ye be warned&lt;/em&gt;&lt;/strong&gt; 🏴‍☠️, but please bear with me 🐻.
Each one is tightly coupled to one another because it is how layout is performed in your browser!
Feel free to skip this section (or any of the sub-sections) if you&amp;#x27;re up to speed on these topics.&lt;/p&gt;&lt;p&gt;Also, keep in mind that this section is pure &lt;strong&gt;&lt;em&gt;background information&lt;/em&gt;&lt;/strong&gt;.
You don&amp;#x27;t &lt;em&gt;need&lt;/em&gt; to read it, but I highly suggest that you do!
It&amp;#x27;s informative and has some cool and insightful interactive examples. 🤓&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;#you-got-your-chocolate-in-my-peanut-butter-&quot;&gt;Skip link&lt;/a&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;#the-box-model&quot;&gt;The Box Model&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;#dom-flow&quot;&gt;DOM Flow&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;#positioning&quot;&gt;Positioning&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;#stacking-contexts&quot;&gt;Stacking Contexts&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For everyone else, let&amp;#x27;s go! 🏌️‍♂️
First, let&amp;#x27;s talk through the box model.&lt;/p&gt;&lt;h4 id=&quot;the-box-model&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-box-model&quot; aria-label=&quot;the box model permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Box Model&lt;/h4&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/boxing.gif&quot; alt=&quot;The boxing model, probably a derivative of or adjacent to border-box 🥁🤷‍♂️😂&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;The boxing model, probably a derivative of or adjacent to border-box 🥁🤷‍♂️😂&lt;/figcaption&gt;&lt;p&gt;In HTML and CSS, everything is a box or rectangle (even circular things)!
You can manipulate each box&amp;#x27;s size, position, and presentational styling using CSS.
According to MDN&amp;#x27;s &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model&quot;&gt;box model docs&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Every box is composed of four parts (or areas), defined by their respective edges: the content edge, padding edge, border edge, and margin edge.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/mdn-box-model.png&quot; alt=&quot;MDN&amp;#x27;s Box Model Graphic&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;MDN&amp;#x27;s Box Model Graphic&lt;/figcaption&gt;&lt;p&gt;You should also be aware of the difference between &lt;code class=&quot;language-text&quot;&gt;inline&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;block&lt;/code&gt; elements.
What&amp;#x27;s described above is directly applicable to &lt;code class=&quot;language-text&quot;&gt;block&lt;/code&gt; elements.
MDN also has a great &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flow_Layout/Block_and_Inline_Layout_in_Normal_Flow#Elements_participating_in_an_inline_formatting_context&quot;&gt;doc&lt;/a&gt; on &lt;code class=&quot;language-text&quot;&gt;inline&lt;/code&gt; vs &lt;code class=&quot;language-text&quot;&gt;block&lt;/code&gt; flow, but the main takeaways are that &lt;code class=&quot;language-text&quot;&gt;inline&lt;/code&gt; elements:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;They are only as big as they need to be, e.g. all of the words or text in this post! Think of them as a box, but shrinkwrapped up nice and tightly to take up as little space as possible.&lt;/li&gt;&lt;li&gt;When placed next to one another, they &lt;em&gt;&amp;quot;flow&amp;quot;&lt;/em&gt; together in the document&amp;#x27;s text direction, e.g. left to right. Think about how words flow together within a paragraph.&lt;/li&gt;&lt;li&gt;They are still &amp;quot;boxes&amp;quot;, but you can&amp;#x27;t determine their size directly. Instead, it&amp;#x27;s inferred from how much &amp;quot;stuff&amp;quot; is inside them!&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Lastly, for understanding the box model, let&amp;#x27;s go through an interactive example of &lt;code class=&quot;language-text&quot;&gt;box-sizing&lt;/code&gt;.
In the following rendering, you can change the properties of each box and see their size and visual properties update in real-time.
It should give you a good idea of how the box model works in general!&lt;/p&gt;&lt;div caption=&quot;[object Object]&quot;&gt;&lt;style data-emotion-css=&quot;1jke4yk&quot;&gt;.css-1jke4yk{position:relative;width:100%;}&lt;/style&gt;&lt;div class=&quot;css-1jke4yk&quot;&gt;&lt;div&gt;&lt;style data-emotion-css=&quot;1x9mqzb&quot;&gt;.css-1x9mqzb{display:block;margin-bottom:0.5rem;}&lt;/style&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Background color: &lt;input type=&quot;text&quot; value=&quot;#303030&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Border color: &lt;input type=&quot;text&quot; value=&quot;#f00&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Border width: &lt;input type=&quot;text&quot; value=&quot;4px&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Color: &lt;input type=&quot;text&quot; value=&quot;#fff&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Height: &lt;input type=&quot;text&quot; value=&quot;80px&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Padding: &lt;input type=&quot;text&quot; value=&quot;20px&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Width: &lt;input type=&quot;text&quot; value=&quot;120px&quot;/&gt;&lt;/label&gt;&lt;p&gt;Note: 1rem === 16px&lt;/p&gt;&lt;/div&gt;&lt;hr/&gt;&lt;h3&gt;Summary&lt;/h3&gt;&lt;style data-emotion-css=&quot;1ierj3f&quot;&gt;.css-1ierj3f{display:grid;grid-gap:1rem;grid-template-columns:1fr 1fr;}&lt;/style&gt;&lt;div class=&quot;css-1ierj3f&quot;&gt;&lt;div&gt;&lt;h4&gt;Content Box&lt;/h4&gt;&lt;p&gt;Height: 0 px&lt;/p&gt;&lt;p&gt;Width: 0 px&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;h4&gt;Border Box&lt;/h4&gt;&lt;p&gt;Height: 0 px&lt;/p&gt;&lt;p&gt;Width: 0 px&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;style data-emotion-css=&quot;erar2m&quot;&gt;.css-erar2m{border:1px dashed;margin:0 auto;padding:1rem;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;}&lt;/style&gt;&lt;div class=&quot;css-erar2m&quot;&gt;&lt;style data-emotion-css=&quot;1ajckju&quot;&gt;.css-1ajckju{border-style:solid;background-color:#303030;border-color:#f00;border-width:4px;color:#fff;height:80px;padding:20px;width:120px;box-sizing:content-box;margin-bottom:1rem;}&lt;/style&gt;&lt;div class=&quot;css-1ajckju&quot;&gt;Content box (initial &amp;amp; default value)&lt;/div&gt;&lt;style data-emotion-css=&quot;7f40f8&quot;&gt;.css-7f40f8{border-style:solid;background-color:#303030;border-color:#f00;border-width:4px;color:#fff;height:80px;padding:20px;width:120px;box-sizing:border-box;}&lt;/style&gt;&lt;div class=&quot;css-7f40f8&quot;&gt;Border box&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h5 id=&quot;box-model-the-takeaway&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#box-model-the-takeaway&quot; aria-label=&quot;box model the takeaway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Box Model: The Takeaway&lt;/h5&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;With HTML and CSS, it&amp;#x27;s boxes all the way down!&lt;/em&gt;&lt;/strong&gt;
Even if it doesn&amp;#x27;t appear that way, everything is a box.
This is part of why the navigation box originally blocked inner pointer interactions!&lt;/p&gt;&lt;p&gt;Next, we&amp;#x27;re drifting into DOM flow. 🌊&lt;/p&gt;&lt;h4 id=&quot;dom-flow&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#dom-flow&quot; aria-label=&quot;dom flow permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;DOM Flow&lt;/h4&gt;&lt;p&gt;For starters, there&amp;#x27;s &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction#Normal_flow&quot;&gt;normal flow&lt;/a&gt;, which MDN says is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Normal flow is how the browser lays out HTML pages by default when you do nothing to control page layout.&lt;/p&gt;&lt;p&gt;Note here how the HTML is displayed in the exact order in which it appears in the source code, with elements stacked up on top of one another&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;By default for English locales (bear with me 🐻, I&amp;#x27;m glossing over a lot of details), the markup is rendered from left to right, top to bottom.
We&amp;#x27;ve already touched on this briefly above in &lt;a href=&quot;#the-box-model&quot;&gt;the box model section&lt;/a&gt;.
Now, you &lt;em&gt;can&lt;/em&gt; stack elements on top of one another visually with CSS, namely through &lt;strong&gt;positioning&lt;/strong&gt; and the use of &lt;strong&gt;stacking contexts&lt;/strong&gt;.
Conveniently, these are the two upcoming sections!&lt;/p&gt;&lt;h5 id=&quot;dom-flow-the-takeaway&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#dom-flow-the-takeaway&quot; aria-label=&quot;dom flow the takeaway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;DOM Flow: The Takeaway&lt;/h5&gt;&lt;p&gt;Without changing any CSS, elements will render in the order that you define them in the DOM (your code).&lt;/p&gt;&lt;p&gt;Now, let&amp;#x27;s &lt;em&gt;position&lt;/em&gt; ourselves to understand the remaining two sections.&lt;/p&gt;&lt;h4 id=&quot;positioning&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#positioning&quot; aria-label=&quot;positioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Positioning&lt;/h4&gt;&lt;blockquote&gt;&lt;p&gt;Position yourself well enough, and circumstances will do the rest&lt;/p&gt;&lt;p&gt;Mason Cooley&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you ever find yourself wanting to do &lt;em&gt;interesting&lt;/em&gt; things with a website (read as to make it pretty and not look like it came out of 1995), then styling paired with positioning will probably be of interest to you.&lt;/p&gt;&lt;p&gt;By default, DOM elements will be rendered with &lt;code class=&quot;language-text&quot;&gt;position: static;&lt;/code&gt;.
You don&amp;#x27;t need to set this, the browser will do it for you!
All it does is makes the element participate in its &lt;em&gt;normal layout behavior&lt;/em&gt;, e.g.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-html line-numbers&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Mr. Booshded Neynaleavun&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Date: September 11, 2001&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;will behave identically to:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-html line-numbers&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt; &lt;span class=&quot;token style-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token style language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; static&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Mr. Booshded Neynaleavun&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt; &lt;span class=&quot;token style-attr&quot;&gt;&lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token style language-css&quot;&gt;&lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; static&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Date: September 11, 2001&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;even though we&amp;#x27;ve explicitly &lt;strong&gt;&lt;em&gt;&amp;quot;positioned&amp;quot;&lt;/em&gt;&lt;/strong&gt; (but, we haven&amp;#x27;t 😉) both elements!&lt;/p&gt;&lt;p&gt;I must sound like a broken record, but again, MDN comes in clutch with amazing docs on &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning&quot;&gt;positioning&lt;/a&gt;.
I&amp;#x27;ll summarize the main points below.
We&amp;#x27;ve already talked about &lt;code class=&quot;language-text&quot;&gt;static&lt;/code&gt; (or default) positioning and while it has its place, it can be rather boring.
In the upcoming subsections, I&amp;#x27;ll explain the gist of &lt;code class=&quot;language-text&quot;&gt;relative&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;absolute&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;fixed&lt;/code&gt; positioning.
I&amp;#x27;ll leave out &lt;code class=&quot;language-text&quot;&gt;position: sticky&lt;/code&gt; for now, just so this post doesn&amp;#x27;t become a full-on DOM layout rendering 101 tutorial 😂.&lt;/p&gt;&lt;h5 id=&quot;top-bottom-left-and-right&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#top-bottom-left-and-right&quot; aria-label=&quot;top bottom left and right permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Top, Bottom, Left, and Right&lt;/h5&gt;&lt;p&gt;When set, these properties are used to &lt;strong&gt;&lt;em&gt;offset&lt;/em&gt;&lt;/strong&gt; an element from its &lt;em&gt;normal&lt;/em&gt; position.
This will make more sense in upcoming examples, I promise.
Read on! 📖&lt;/p&gt;&lt;h5 id=&quot;relative-positioning&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#relative-positioning&quot; aria-label=&quot;relative positioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Relative Positioning&lt;/h5&gt;&lt;p&gt;Relative positioning can take a second to wrap your head around, but once you get it it&amp;#x27;s really neat.&lt;/p&gt;&lt;p&gt;So, remember how&lt;code class=&quot;language-text&quot;&gt;static&lt;/code&gt; positioning just means &amp;quot;Hey browser, put me where I fit&amp;quot;?
Well, &lt;code class=&quot;language-text&quot;&gt;relative&lt;/code&gt; positioning behaves the same.&lt;/p&gt;&lt;p&gt;&lt;em&gt;Until you set &lt;code class=&quot;language-text&quot;&gt;top&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;right&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;bottom&lt;/code&gt;, and/or &lt;code class=&quot;language-text&quot;&gt;left&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;&lt;p&gt;When you set one or more of those properties (assuming to a non-zero, default value), then the &lt;code class=&quot;language-text&quot;&gt;position: relative;&lt;/code&gt; element will shift in the direction you told it by the amount you told it to!&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s an interactive example to drive this point home.
Try setting the &lt;code class=&quot;language-text&quot;&gt;top&lt;/code&gt; field to &lt;code class=&quot;language-text&quot;&gt;-4rem&lt;/code&gt;, for example.
What do you see? 👀
What happens if you turn off position relative, but still set one of the positional properties, e.g. &lt;code class=&quot;language-text&quot;&gt;top&lt;/code&gt;?&lt;/p&gt;&lt;div caption=&quot;[object Object]&quot;&gt;&lt;style data-emotion-css=&quot;jqtfa0&quot;&gt;.css-jqtfa0{position:relative;z-index:100;}&lt;/style&gt;&lt;div class=&quot;css-jqtfa0&quot;&gt;&lt;style data-emotion-css=&quot;1x9mqzb&quot;&gt;.css-1x9mqzb{display:block;margin-bottom:0.5rem;}&lt;/style&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Use position relative? &lt;input type=&quot;checkbox&quot; checked=&quot;&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;&lt;style data-emotion-css=&quot;17vg255&quot;&gt;.css-17vg255{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;-webkit-flex-flow:row wrap;-ms-flex-flow:row wrap;flex-flow:row wrap;list-style:none;margin:0;}&lt;/style&gt;&lt;ul class=&quot;css-17vg255&quot;&gt;&lt;li&gt;Top: &lt;style data-emotion-css=&quot;1yq544w&quot;&gt;.css-1yq544w{width:4rem;}&lt;/style&gt;&lt;input type=&quot;text&quot; value=&quot;0&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Right: &lt;input type=&quot;text&quot; value=&quot;0&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Bottom: &lt;input type=&quot;text&quot; value=&quot;0&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Left: &lt;input type=&quot;text&quot; value=&quot;0&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Background color: &lt;input type=&quot;text&quot; value=&quot;#e0e0e0&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Color: &lt;input type=&quot;text&quot; value=&quot;#000&quot;/&gt;&lt;/label&gt;&lt;p&gt;Note: the movable element below will appear below these form elements on purpose &lt;span role=&quot;img&quot; aria-label=&quot;wink face emoji&quot;&gt;😉&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;style data-emotion-css=&quot;14pl9kr&quot;&gt;.css-14pl9kr{width:100%;border:0.25rem solid black;padding:1rem;}&lt;/style&gt;&lt;div class=&quot;css-14pl9kr&quot;&gt;&lt;p&gt;Dolor quis excepteur dolor cillum ipsum cupidatat incididunt tempor non cillum anim irure occaecat.&lt;/p&gt;&lt;style data-emotion-css=&quot;8sj82m&quot;&gt;.css-8sj82m{background-color:#e0e0e0;color:#000;position:relative;,top:0;right:0;bottom:0;left:0;}&lt;/style&gt;&lt;p class=&quot;css-8sj82m&quot;&gt;Move me around!&lt;/p&gt;&lt;p&gt;Fugiat velit est proident nostrud consequat est quis excepteur exercitation exercitation labore.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Note: positioning direction with &lt;code class=&quot;language-text&quot;&gt;top&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;right&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;bottom&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;left&lt;/code&gt; follows a potentially confusing pattern.
If you give one of those properties a &lt;strong&gt;&lt;em&gt;positive&lt;/em&gt;&lt;/strong&gt; value, it shifts the element in the &lt;strong&gt;&lt;em&gt;opposite&lt;/em&gt;&lt;/strong&gt; direction, e.g. &lt;code class=&quot;language-text&quot;&gt;top: 10px&lt;/code&gt; will not move the element &lt;strong&gt;UP&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;10px&lt;/code&gt;, but instead &lt;strong&gt;DOWN&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;10px&lt;/code&gt;.
&lt;strong&gt;&lt;em&gt;Negative&lt;/em&gt;&lt;/strong&gt; values shift the element in the specified direction, e.g. &lt;code class=&quot;language-text&quot;&gt;top: -10px&lt;/code&gt; will move the element &lt;strong&gt;UP&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;10px&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Notice that the &lt;code class=&quot;language-text&quot;&gt;Move me around!&lt;/code&gt; element appears to hover over other elements (except for the form elements 😉).
This is a cool side-effect is of setting &lt;code class=&quot;language-text&quot;&gt;position: relative;&lt;/code&gt;: you get a &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; for free.
It&amp;#x27;s really &lt;code class=&quot;language-text&quot;&gt;z-index = 0&lt;/code&gt;, but it becomes and appears positioned above static elements!
This will come in handy down below in the &lt;a href=&quot;#stacking-contexts&quot;&gt;stacking contexts subsection&lt;/a&gt;.&lt;/p&gt;&lt;h5 id=&quot;absolute-positioning&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#absolute-positioning&quot; aria-label=&quot;absolute positioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Absolute Positioning&lt;/h5&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0010-cool-ui-tricks-pointer-event-passthrough-on-my-sites-primary-navigation/images/only-a-sith-deals-in-absolutes.gif&quot; alt=&quot;Only a Sith deals in absolutes.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Only a Sith deals in absolutes.&lt;/figcaption&gt;&lt;p&gt;Unlike &lt;code class=&quot;language-text&quot;&gt;relative&lt;/code&gt;, an &lt;code class=&quot;language-text&quot;&gt;absolute&lt;/code&gt; element no longer exists in the normal DOM flow.
Instead, it is bound to its &lt;strong&gt;&lt;em&gt;containing element&lt;/em&gt;&lt;/strong&gt;.
The &lt;em&gt;containing element&lt;/em&gt; is determined by a fancy algorithm described &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#Identifying_the_containing_block&quot;&gt;here&lt;/a&gt;.
Basically, for &lt;code class=&quot;language-text&quot;&gt;position: absolute;&lt;/code&gt;, the containing element is generally (here comes &lt;del&gt;dat boi 🐸&lt;/del&gt; the nuance) nearest ancestor whose &lt;code class=&quot;language-text&quot;&gt;position&lt;/code&gt; is &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;static&lt;/code&gt;.
If one doesn&amp;#x27;t exist, it becomes the &lt;strong&gt;&lt;em&gt;initial containing block&lt;/em&gt;&lt;/strong&gt;, which is the block that contains the &lt;code class=&quot;language-text&quot;&gt;documentElement&lt;/code&gt;, or the &lt;code class=&quot;language-text&quot;&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tag.
The initial containing block has the size of the browser viewport.&lt;/p&gt;&lt;p&gt;As is tradition, here&amp;#x27;s an interactive example! 💃
Which element is the &lt;strong&gt;&lt;em&gt;containing element&lt;/em&gt;&lt;/strong&gt; of the &lt;code class=&quot;language-text&quot;&gt;position: absolute&lt;/code&gt;&amp;#x27;d one?&lt;/p&gt;&lt;div caption=&quot;[object Object]&quot;&gt;&lt;style data-emotion-css=&quot;jqtfa0&quot;&gt;.css-jqtfa0{position:relative;z-index:100;}&lt;/style&gt;&lt;div class=&quot;css-jqtfa0&quot;&gt;&lt;style data-emotion-css=&quot;1x9mqzb&quot;&gt;.css-1x9mqzb{display:block;margin-bottom:0.5rem;}&lt;/style&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Use position absolute? &lt;input type=&quot;checkbox&quot; checked=&quot;&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;&lt;style data-emotion-css=&quot;70vzt1&quot;&gt;.css-70vzt1{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:&quot;justify; flow: row wrap; list-style: none; margin: 0;-webkit-justify-content:&quot;space-between; flex-flow: row wrap; list-style: none; margin: 0;-ms-flex-pack:&quot;justify; flow: row wrap; list-style: none; margin: 0;justify-content:&quot;space-between; flex-flow: row wrap; list-style: none; margin: 0;}&lt;/style&gt;&lt;ul class=&quot;css-70vzt1&quot;&gt;&lt;li&gt;Top: &lt;style data-emotion-css=&quot;1yq544w&quot;&gt;.css-1yq544w{width:4rem;}&lt;/style&gt;&lt;input type=&quot;text&quot; value=&quot;-10px&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Right: &lt;input type=&quot;text&quot; value=&quot;&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Bottom: &lt;input type=&quot;text&quot; value=&quot;&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;li&gt;Left: &lt;input type=&quot;text&quot; value=&quot;-20px&quot; class=&quot;css-1yq544w&quot;/&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Background color: &lt;input type=&quot;text&quot; value=&quot;#e0e0e0&quot;/&gt;&lt;/label&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Color: &lt;input type=&quot;text&quot; value=&quot;#000&quot;/&gt;&lt;/label&gt;&lt;p&gt;Note: the movable element below will appear below these form elements on purpose &lt;span role=&quot;img&quot; aria-label=&quot;wink face emoji&quot;&gt;😉&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;style data-emotion-css=&quot;ud8z5j&quot;&gt;.css-ud8z5j{width:100%;border:0.25rem solid black;padding:1rem;position:relative;}&lt;/style&gt;&lt;div class=&quot;css-ud8z5j&quot;&gt;&lt;p&gt;Dolor quis excepteur dolor cillum ipsum cupidatat incididunt tempor non cillum anim irure occaecat.&lt;/p&gt;&lt;style data-emotion-css=&quot;1271qo3&quot;&gt;.css-1271qo3{background-color:#e0e0e0;color:#000;position:absolute;top:-10px;left:-20px;}&lt;/style&gt;&lt;p class=&quot;css-1271qo3&quot;&gt;Move me around!&lt;/p&gt;&lt;p&gt;Fugiat velit est proident nostrud consequat est quis excepteur exercitation exercitation labore.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Play around with the positional attributes &lt;code class=&quot;language-text&quot;&gt;top&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;right&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;bottom&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;left&lt;/code&gt; to get a feel for how the position of the &lt;code class=&quot;language-text&quot;&gt;Move me around!&lt;/code&gt; element works.
For those playing along, the div (box) with the solid black border is &lt;code class=&quot;language-text&quot;&gt;position: relative&lt;/code&gt;, so it is the &lt;strong&gt;&lt;em&gt;containing element&lt;/em&gt;&lt;/strong&gt; of the &lt;code class=&quot;language-text&quot;&gt;Move me around!&lt;/code&gt; element.
This is because it is the first parent that isn&amp;#x27;t &lt;code class=&quot;language-text&quot;&gt;position: static&lt;/code&gt;!&lt;/p&gt;&lt;p&gt;Fun fact: the starry background in my site&amp;#x27;s navigation is set to &lt;code class=&quot;language-text&quot;&gt;position: absolute;&lt;/code&gt;.
Can you guess what its containing element is? 🤔&lt;/p&gt;&lt;h5 id=&quot;fixed-positioning&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#fixed-positioning&quot; aria-label=&quot;fixed positioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fixed Positioning&lt;/h5&gt;&lt;p&gt;This is similar to &lt;code class=&quot;language-text&quot;&gt;position: absolute;&lt;/code&gt;, except instead of being offset relative to its parent, a &lt;code class=&quot;language-text&quot;&gt;fixed&lt;/code&gt; positioned element is offset relative to the browser viewport (bounds).
I haven&amp;#x27;t used this in my navigation code, but I figured I&amp;#x27;d call it out since it&amp;#x27;s useful! 🗣&lt;/p&gt;&lt;h5 id=&quot;positioning-the-takeaway&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#positioning-the-takeaway&quot; aria-label=&quot;positioning the takeaway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Positioning: The Takeaway&lt;/h5&gt;&lt;p&gt;Positioning is one tool in our toolbox for massaging the DOM into the correct looking shape that we desire. It allows you to do cool things like move things around and stack elements on top of others (like for a modal, popup, or tooltip).&lt;/p&gt;&lt;p&gt;And finally, it&amp;#x27;s time to &lt;em&gt;rack em&amp;#x27;, &lt;strong&gt;stack&lt;/strong&gt; em&amp;#x27;, and pack em&amp;#x27;&lt;/em&gt;.&lt;/p&gt;&lt;h4 id=&quot;stacking-contexts&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#stacking-contexts&quot; aria-label=&quot;stacking contexts permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Stacking Contexts&lt;/h4&gt;&lt;blockquote&gt;&lt;p&gt;You can do anything with stacks and iteration that you can do with recursion&lt;/p&gt;&lt;p&gt;Steve McConnell&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;As we saw when discussing &lt;a href=&quot;#positioning&quot;&gt;positioning&lt;/a&gt;, &lt;em&gt;positioned elements win over non-positioned elements&lt;/em&gt;.
In cases where there are multiple positioned elements, the way to control which has overlapping precedence is with the &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; CSS property. The &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; CSS property is an integer value that describes how &amp;quot;high&amp;quot; the element would be elevated off the page if it were in 3D space.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s check out a simple interactive stacking example.
There&amp;#x27;s a non-positioned (i.e. &lt;code class=&quot;language-text&quot;&gt;position: static&lt;/code&gt;) blue box, a red &lt;code class=&quot;language-text&quot;&gt;position: relative&lt;/code&gt; box at &lt;code class=&quot;language-text&quot;&gt;z-index: 2&lt;/code&gt;, and a green box that you can control which defaults to &lt;code class=&quot;language-text&quot;&gt;z-index: 1&lt;/code&gt;.
At the start, the red box is visually &amp;quot;on top&amp;quot; of the other two boxes, followed by the green box, and finally the blue box.
What happens when you set the green box&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; to 2? To 3? To 0?&lt;/p&gt;&lt;div caption=&quot;[object Object]&quot;&gt;&lt;style data-emotion-css=&quot;1x9mqzb&quot;&gt;.css-1x9mqzb{display:block;margin-bottom:0.5rem;}&lt;/style&gt;&lt;label class=&quot;css-1x9mqzb&quot;&gt;Green zIndex: &lt;input type=&quot;number&quot; value=&quot;1&quot;/&gt;&lt;/label&gt;&lt;style data-emotion-css=&quot;1gskaep&quot;&gt;.css-1gskaep{width:100%;height:16rem;}&lt;/style&gt;&lt;div class=&quot;css-1gskaep&quot;&gt;&lt;style data-emotion-css=&quot;1ojo3f8&quot;&gt;.css-1ojo3f8{width:10rem;height:10rem;background-color:#1976d2;}&lt;/style&gt;&lt;div class=&quot;css-1ojo3f8&quot;&gt;Blue&lt;/div&gt;&lt;style data-emotion-css=&quot;pjsiri&quot;&gt;.css-pjsiri{width:10rem;height:10rem;background-color:#d32f2f;position:relative;z-index:2;top:-8rem;right:-4rem;}&lt;/style&gt;&lt;div class=&quot;css-pjsiri&quot;&gt;Red&lt;/div&gt;&lt;style data-emotion-css=&quot;1c5wm1l&quot;&gt;.css-1c5wm1l{width:10rem;height:10rem;background-color:#388e3c;position:relative;z-index:1;top:-14rem;}&lt;/style&gt;&lt;div class=&quot;css-1c5wm1l&quot;&gt;Green&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h5 id=&quot;stacking-contexts-the-takeaway&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#stacking-contexts-the-takeaway&quot; aria-label=&quot;stacking contexts the takeaway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Stacking Contexts: The Takeaway&lt;/h5&gt;&lt;p&gt;We saw before in the &lt;a href=&quot;#positioning&quot;&gt;positioning section&lt;/a&gt; that anything that isn&amp;#x27;t &lt;code class=&quot;language-text&quot;&gt;position: static&lt;/code&gt; has the ability to use &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt;.
The &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; CSS property allows you to manage how elements overlap others.
The higher the &lt;code class=&quot;language-text&quot;&gt;z-index&lt;/code&gt; (if not &lt;code class=&quot;language-text&quot;&gt;position: static&lt;/code&gt;), the more likely an element will visually appear on top of others.&lt;/p&gt;&lt;h2 id=&quot;you-got-your-chocolate-in-my-peanut-butter-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#you-got-your-chocolate-in-my-peanut-butter-&quot; aria-label=&quot;you got your chocolate in my peanut butter  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;You Got Your Chocolate in my Peanut Butter 😔&lt;/h2&gt;&lt;p&gt;Does it make sense to use CSS for disabling an element and its children&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;pointer-events&lt;/code&gt;?
It seems kind of odd to me that such behavior is delegated to CSS instead of Javascript.
I mean, it&amp;#x27;s not like &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/cursor&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;cursor: pointer&lt;/code&gt;&lt;/a&gt; where it&amp;#x27;s a &lt;strong&gt;&lt;em&gt;purely &amp;quot;presentational&amp;quot;&lt;/em&gt;&lt;/strong&gt; effect.
With Javascript, (examples following being of the React flavor) you enhance DOM elements by adding &lt;code class=&quot;language-text&quot;&gt;event listeners&lt;/code&gt; which trigger on interactions providing the desired functionality.
By setting &lt;code class=&quot;language-text&quot;&gt;pointer-events: none;&lt;/code&gt; on a DOM element, you are turning off all cursor interactions for &lt;strong&gt;&lt;em&gt;it and its children!&lt;/em&gt;&lt;/strong&gt;
This is crazy to me! 😜
Sounds an awful lot like a Javascript concern, namely something like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;DestroyAllClicks&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;count&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setCount&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;increment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setCount&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; c &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;preventAllClicks&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stopPropagation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div onClickCapture&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;preventAllClicks&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;button&amp;quot;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;increment&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        Increment count
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Count &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;count&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div caption=&quot;Interactive example: prevent all click handlers from processing in children using Javascript&quot;&gt;&lt;style data-emotion-css=&quot;xi606m&quot;&gt;.css-xi606m{text-align:center;}&lt;/style&gt;&lt;div class=&quot;css-xi606m&quot;&gt;&lt;button type=&quot;button&quot;&gt;Increment count&lt;/button&gt;&lt;p&gt;Count = 0&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;It pushes me further and further from the &lt;em&gt;misguided&lt;/em&gt; belief that your &lt;del&gt;peanut butter shouldn&amp;#x27;t mix with my chocolate&lt;/del&gt; UI concerns should be separated.
The lines are so blurred now.
Javascript isn&amp;#x27;t just for adding &lt;em&gt;&amp;quot;functionality&amp;quot;&lt;/em&gt;, it&amp;#x27;s also for rendering and animations.
CSS isn&amp;#x27;t just for presentational styling, it&amp;#x27;s also for interactivity/functionality.
And with web components, well, the lines continue to be blurred!&lt;/p&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I strive for great UX, but it&amp;#x27;s a constant battle.
This site, as of writing this article, still has a long way to go, but &lt;strong&gt;&lt;em&gt;iterators gonna iterate&lt;/em&gt;&lt;/strong&gt;.
It&amp;#x27;s all too easy to get caught up in the technical details when developing something.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;What should &lt;code class=&quot;language-text&quot;&gt;${it}&lt;/code&gt; do?&lt;/li&gt;&lt;li&gt;What are the requirements?&lt;/li&gt;&lt;li&gt;Do you provide a good user experience?&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Initially, I thought I hit the mark for my navigation bar (technically I still haven&amp;#x27;t because my mobile nav is atrocious 😲🤷‍♂️😂).
But, only by taking a step back and looking at the full context of where the navigation was rendered and how it should interact with its adjacent elements (in the DOM order or stacking order) was I able to fully address my requirements and provide a good user experience.
And I got to learn about and use a cool, but odd CSS property along the way!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Indifferent With Ruby Hashes]]></title><description><![CDATA[I miss plain old JavaScript objects... 😔 sigh  Ruby hashes A Ruby  hash  is a  key-value pair  container which can be made with either a…]]></description><link>https://codyaprice.com/blog/indifferent-with-ruby-hashes/</link><guid isPermaLink="false">https://codyaprice.com/blog/indifferent-with-ruby-hashes/</guid><pubDate>Fri, 13 Dec 2019 20:41:12 GMT</pubDate><content:encoded>&lt;p&gt;I miss plain old JavaScript objects... 😔&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;sigh-ruby-hashes&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#sigh-ruby-hashes&quot; aria-label=&quot;sigh ruby hashes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;sigh&lt;/em&gt;&lt;/strong&gt; Ruby hashes&lt;/h2&gt;&lt;p&gt;A Ruby &lt;code class=&quot;language-text&quot;&gt;hash&lt;/code&gt; is a &lt;strong&gt;&lt;em&gt;key-value pair&lt;/em&gt;&lt;/strong&gt; container which can be made with either a &lt;code class=&quot;language-text&quot;&gt;hash&lt;/code&gt; literal &lt;code class=&quot;language-text&quot;&gt;{}&lt;/code&gt; or constructor &lt;code class=&quot;language-text&quot;&gt;Hash.new&lt;/code&gt;.
They&amp;#x27;re known as &lt;em&gt;dictionaries&lt;/em&gt; or &lt;em&gt;associative-arrays&lt;/em&gt; and allow you to store &lt;strong&gt;&lt;em&gt;values&lt;/em&gt;&lt;/strong&gt; that can be accessed by a &lt;strong&gt;&lt;em&gt;key&lt;/em&gt;&lt;/strong&gt;.
If you&amp;#x27;re acquainted with &lt;a href=&quot;https://www.json.org/json-en.html&quot;&gt;JSON&lt;/a&gt; or &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object&quot;&gt;JavaScript objects&lt;/a&gt;, this should look familiar.
When it comes to values, they can be anything, even other nested hashes!
Keys are generally either &lt;code class=&quot;language-text&quot;&gt;string&lt;/code&gt;s or &lt;code class=&quot;language-text&quot;&gt;symbol&lt;/code&gt;s (like a Ruby &lt;code class=&quot;language-text&quot;&gt;string&lt;/code&gt;, &lt;em&gt;but stronk&lt;/em&gt;, &lt;a href=&quot;https://ruby-doc.org/core-2.6.5/Symbol.html&quot;&gt;docs here&lt;/a&gt;) for simplicity, but you can use anything that is an &lt;em&gt;&amp;quot;object type&amp;quot;&lt;/em&gt;.
Reaching for the &lt;a href=&quot;https://ruby-doc.org/core-2.6.5/Hash.html#class-Hash-label-Hash+Keys&quot;&gt;Ruby docs&lt;/a&gt;, we see that:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A user-defined class may be used as a hash key if the &lt;code class=&quot;language-text&quot;&gt;hash&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;eql?&lt;/code&gt; methods are overridden to provide meaningful behavior. By default, separate instances refer to separate hash keys.&lt;/p&gt;&lt;p&gt;A typical implementation of &lt;code class=&quot;language-text&quot;&gt;hash&lt;/code&gt; is based on the object&amp;#x27;s data while &lt;code class=&quot;language-text&quot;&gt;eql?&lt;/code&gt; is usually aliased to the overridden &lt;code class=&quot;language-text&quot;&gt;==&lt;/code&gt; method&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This just means many things, even complex objects you or others write, can evaluate to hash keys.&lt;/p&gt;&lt;h2 id=&quot;accessing-hash-values&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#accessing-hash-values&quot; aria-label=&quot;accessing hash values permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Accessing Hash Values&lt;/h2&gt;&lt;p&gt;In the beginning, I mentioned that hashes are referred to as &lt;em&gt;associative-arrays&lt;/em&gt;.
This is because while arrays, or lists of items, are indexed by numbers, e.g.:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-ruby line-numbers&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# list has 3 items (a .length equal to 3)&lt;/span&gt;
list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;first&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;second&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;third&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# notice below that we are accessing the list items by a number index&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# ruby arrays use 0-based indexing, or the first item is the 0th index&lt;/span&gt;
first &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; list&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
second &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; list&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;hashes, on the other hand, use &lt;strong&gt;&lt;em&gt;generic&lt;/em&gt;&lt;/strong&gt; keys, e.g.:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-ruby line-numbers&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# declare a new hash using a hash literal&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# I&amp;#x27;m only using strings as values here, but&lt;/span&gt;
hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  nested&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string&quot;&gt;&amp;quot;look ma&amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;I&amp;#x27;m in a nested hash!&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  foo&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# symbol notation&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;three&amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# fat arrow notation, which is necessary for string and number keys&lt;/span&gt;
  &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;four&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# get the nested hash using a symbol key&lt;/span&gt;
nested_hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:nested&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# get the three value using a string&lt;/span&gt;
three &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;three&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# we can even use numbers as keys!&lt;/span&gt;
four &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;wheres-the-beef-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#wheres-the-beef-&quot; aria-label=&quot;wheres the beef  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Where&amp;#x27;s the beef? 🐄&lt;/h2&gt;&lt;p&gt;So far, hashes look pretty neat, right?
Well, for the most part, they are.
They&amp;#x27;re used &lt;strong&gt;&lt;em&gt;all the time&lt;/em&gt;&lt;/strong&gt;, especially in Rails applications.
However, what do you think happens when you try the following?&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-ruby line-numbers&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  foo&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;bar&amp;quot;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# a symbol key, :foo&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# notice: the foo key is a symbol,&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# but instead we&amp;#x27;re trying to access using a string&lt;/span&gt;
foo &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The answer?&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0009-indifferent-with-ruby-hashes/images/example-hash-access-using-a-string-when-key-is-a-symbol.png&quot; alt=&quot;Example: Hash access using a string when the key is a symbol&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Example: Hash access using a string when the key is a symbol&lt;/figcaption&gt;&lt;p&gt;We can&amp;#x27;t access the &lt;code class=&quot;language-text&quot;&gt;foo&lt;/code&gt; value using the string &lt;code class=&quot;language-text&quot;&gt;&amp;quot;foo&amp;quot;&lt;/code&gt;, but instead have to use the symbol &lt;code class=&quot;language-text&quot;&gt;:foo&lt;/code&gt;.
Mildly put, this is annoying.&lt;/p&gt;&lt;p&gt;Coming from JavaScript land, objects have &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015&quot;&gt;shorthand property names&lt;/a&gt;, which looks strikingly similar to symbol notation for Ruby hash keys:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  foo&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;bar&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// accessing with object destructuring works&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; foo &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// as does with a string works&lt;/span&gt;
foo &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;foo&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// as does named property access&lt;/span&gt;
foo &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;foo&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0009-indifferent-with-ruby-hashes/images/example-node-object-access.png&quot; alt=&quot;Example: Node object access&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Example: Node object access&lt;/figcaption&gt;&lt;p&gt;Keep in mind that I&amp;#x27;ve purposefully left out ES2015 &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Symbol&quot;&gt;Symbols&lt;/a&gt;, as they are &lt;em&gt;different from Ruby symbols&lt;/em&gt;.
Mainly, they don&amp;#x27;t coerce to strings easily.
And, when converting them to strings using &lt;code class=&quot;language-text&quot;&gt;.toString()&lt;/code&gt;, for example, they produce &lt;code class=&quot;language-text&quot;&gt;&amp;quot;Symbol(&amp;lt;VALUE&amp;gt;)&amp;quot;&lt;/code&gt;, e.g.:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0009-indifferent-with-ruby-hashes/images/example-demonstrating-js-symbols.png&quot; alt=&quot;Example: Demonstrating JS Symbols&quot;/&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;What do you want Cody?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0009-indifferent-with-ruby-hashes/images/ill-tell-you-what-i-want.gif&quot; alt=&quot;I&amp;#x27;ll tell you what I want, what I really really want!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;I&amp;#x27;ll tell you what I want, what I really really want!&lt;/figcaption&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-ruby line-numbers&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;bar&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

this &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token symbol&quot;&gt;:foo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
that &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; hash&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

this &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; that &lt;span class=&quot;token comment&quot;&gt;#=&amp;gt; true&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;rails-to-the-rescue-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#rails-to-the-rescue-&quot; aria-label=&quot;rails to the rescue  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Rails to the Rescue 🛤&lt;/h2&gt;&lt;p&gt;Rails has a weird symbiotic relationship with Ruby and will constantly &lt;a href=&quot;https://culttt.com/2015/06/17/what-is-monkey-patching-in-ruby/&quot;&gt;monkey-patch&lt;/a&gt; the core library, or at least provide extensions to it.
The extension that will save us is &lt;a href=&quot;https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html&quot;&gt;ActiveSupport::HashWithIndifferentAccess&lt;/a&gt;, where:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Implements a &lt;code class=&quot;language-text&quot;&gt;hash&lt;/code&gt; where keys &lt;code class=&quot;language-text&quot;&gt;:foo&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;&amp;quot;foo&amp;quot;&lt;/code&gt; are considered to be the same.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;A hash of this type can be made either using:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-ruby line-numbers&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# the ActiveSupport::HashWithIndifferentAccess constructor&lt;/span&gt;
hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;ActiveSupport&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;HashWithIndifferentAccess&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# or, a hash literal followed by `.with_indifferent_access`&lt;/span&gt;
hash &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;with_indifferent_access&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here it is in action:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0009-indifferent-with-ruby-hashes/images/example-hash-with-indifferent-access.png&quot; alt=&quot;Example: Using the Rails Hash With Indifferent Access Extension&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Example: Using the Rails Hash With Indifferent Access Extension&lt;/figcaption&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;And I LOVE it&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;TLDR: Indifferent access hashes are what hashes should have been in the first place.&lt;/p&gt;&lt;p&gt;I shouldn&amp;#x27;t have to care whether you give a hash &lt;code class=&quot;language-text&quot;&gt;:foo&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;&amp;quot;foo&amp;quot;&lt;/code&gt; to access something.
&lt;strong&gt;&lt;em&gt;Both of those cases should behave identically&lt;/em&gt;&lt;/strong&gt;.
If it did, APIs that return hashes wouldn&amp;#x27;t need to use something like &lt;a href=&quot;https://api.rubyonrails.org/classes/Hash.html#method-i-deep_symbolize_keys-21&quot;&gt;deep_symbolize_keys&lt;/a&gt;.
Also, why are these highly valuable things not in Ruby core yet??&lt;/p&gt;&lt;p&gt;And that&amp;#x27;s why I miss POJOs: Plain Old JavaScript Objects.
And why I&amp;#x27;m so &lt;strong&gt;&lt;em&gt;indifferent&lt;/em&gt;&lt;/strong&gt; 😉with Ruby hashes.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Sort it out, JS 😒]]></title><description><![CDATA[Fell for the ol' default JavaScript sorting algorithm trap when working with numbers. 😲 It's been a little while since my last post (about…]]></description><link>https://codyaprice.com/blog/sort-it-out-js/</link><guid isPermaLink="false">https://codyaprice.com/blog/sort-it-out-js/</guid><pubDate>Thu, 12 Dec 2019 02:59:09 GMT</pubDate><content:encoded>&lt;p&gt;Fell for the ol&amp;#x27; default JavaScript sorting algorithm trap when working with numbers. 😲&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;It&amp;#x27;s been a little while since my last post (about a month and a half).
This wasn&amp;#x27;t intentional since I have a lot of things in flight right now.
That being said, I &lt;strong&gt;&lt;em&gt;do&lt;/em&gt;&lt;/strong&gt; have a lot of things in the pipeline for upcoming posts.&lt;/p&gt;&lt;p&gt;Tonight I made a script to &lt;a href=&quot;https://automatetheboringstuff.com/&quot;&gt;automate the boring stuff&lt;/a&gt; when creating a blog post.
It&amp;#x27;s a small-&lt;em&gt;ish&lt;/em&gt; node driven command line script that &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/blob/3105787df9d879252b198a5e719817b20c6c2b64/scripts/new-post/index.js&quot;&gt;scaffolds&lt;/a&gt; out a new blog post using a template.
In my website&amp;#x27;s repo, like most (if not all) Gatsby driven static sites, my &lt;a href=&quot;https://codyaprice.com/blog&quot;&gt;posts&lt;/a&gt; are located under &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/tree/3105787df9d879252b198a5e719817b20c6c2b64/content/blog&quot;&gt;content/blog&lt;/a&gt;.
The directory names for each are prefixed with a zero-padded index, followed by a kebab-cased path (which is generally similar to the title and happens to be what makes up the slug).&lt;/p&gt;&lt;p&gt;For example, &lt;code class=&quot;language-text&quot;&gt;0005-git-commit-m-write-more&lt;/code&gt;, which maps to &lt;a href=&quot;https://codyaprice.com/blog/git-commit-m-write-more&quot;&gt;this post&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;For each new post I make, I simply increment that prefix number for superficial sorting within my &lt;code class=&quot;language-text&quot;&gt;content/blog&lt;/code&gt; directory.
While I do &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/blob/3105787df9d879252b198a5e719817b20c6c2b64/gatsby-node.js#L10&quot;&gt;order them by date&lt;/a&gt; on my site, I like seeing my directory listed in posted order, since without the number prefix, the order is alphabetical.
While alphabetical is fine, I&amp;#x27;m gaming the system since numbers are &lt;em&gt;&amp;quot;alphabetically before&amp;quot;&lt;/em&gt; letters.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0008-sort-it-out-js/images/sorted-dir.png&quot; alt=&quot;Sorted blog directory&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Sorted blog directory&lt;/figcaption&gt;&lt;p&gt;Given the above context, my next blog post will be prefixed with &lt;code class=&quot;language-text&quot;&gt;&amp;quot;0009&amp;quot;&lt;/code&gt;.&lt;/p&gt;&lt;h2 id=&quot;who-wants-to-be-a-javascriptonaire&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#who-wants-to-be-a-javascriptonaire&quot; aria-label=&quot;who wants to be a javascriptonaire permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Who Wants to be a JavaScriptonaire?&lt;/h2&gt;&lt;p&gt;So, what did I fall for?
Well, to explain, let&amp;#x27;s play a game.
The stakes are high.
The prize... &lt;em&gt;knawwwledge&lt;/em&gt;.
Let&amp;#x27;s consider the following code snippet:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sortedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Sorting a list of numbers in JavaScript.&lt;/figcaption&gt;&lt;p&gt;What will the result of the &lt;code class=&quot;language-text&quot;&gt;sortedList&lt;/code&gt; variable be?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;(A):&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;(B):&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;[1, 10, 2, 3, 4, 5, 6, 7, 8, 9]&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;(C):&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;&amp;quot;Bush did 911&amp;quot;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;(D):&lt;/strong&gt; None of the above&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I&amp;#x27;ll wait...
No peeking 🙈.
Or, you can cheat and &lt;a href=&quot;#the-correct-answer-is&quot;&gt;scroll down to the answer 😉&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0008-sort-it-out-js/images/countdown.gif&quot; alt=&quot;countdown from 60 seconds&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Countdown from 60 seconds ⏳&lt;/figcaption&gt;&lt;h2 id=&quot;arrayprototypesortof&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#arrayprototypesortof&quot; aria-label=&quot;arrayprototypesortof permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Array.prototype.sort(of?)&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s go to my favorite site south of Reddit, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort&quot;&gt;MDN&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;sort()&lt;/code&gt; method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending, &lt;strong&gt;&lt;em&gt;built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Emphasis mine.
Did you catch it?
While there are plenty of things to talk about here (like sorting in &lt;a href=&quot;https://twitter.com/_jayphelps/status/1196249744902967296&quot;&gt;place&lt;/a&gt;), let&amp;#x27;s focus on what happens when you don&amp;#x27;t provide your comparator function.
Let&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;.reverse()&lt;/code&gt; and replay that back:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So, the following list of numbers from ten down to one will be converted into strings when sorted.
Let&amp;#x27;s pretend we can see &lt;em&gt;pseudo-intermediary steps&lt;/em&gt;, so that:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sortedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Sorting a list of numbers in JavaScript.&lt;/figcaption&gt;&lt;p&gt;turns into &lt;em&gt;something like&lt;/em&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// convert list of numbers to strings&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; listAsStrings &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;10&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;9&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;8&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;7&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;6&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;5&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;4&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;3&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;2&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;1&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// sort the list, convert back into numbers&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sortedList &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; listAsStrings&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Sorting a list of numbers in JavaScript, but with pretend intermediary steps shown.&lt;/figcaption&gt;&lt;p&gt;Again, the default &lt;code class=&quot;language-text&quot;&gt;.sort()&lt;/code&gt; behavior is:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;comparing their sequences of UTF-16 code units values&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;which means that a &lt;strong&gt;&lt;em&gt;comparison&lt;/em&gt;&lt;/strong&gt; between two strings in the list is done character by character (really, &lt;a href=&quot;https://en.wikipedia.org/wiki/Code_point&quot;&gt;code point&lt;/a&gt; by code point) until one of them is considered alphabetically before the other, e.g. &lt;code class=&quot;language-text&quot;&gt;&amp;quot;abc&amp;quot;&lt;/code&gt; comes alphabetically before &lt;code class=&quot;language-text&quot;&gt;&amp;quot;xyz&amp;quot;&lt;/code&gt;.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;the-correct-answer-is&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-correct-answer-is&quot; aria-label=&quot;the correct answer is permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Correct Answer Is...&lt;/h2&gt;&lt;p&gt;If you answered &lt;strong&gt;(A)&lt;/strong&gt;, you&amp;#x27;re...&lt;/p&gt;&lt;p&gt;...&lt;strong&gt;&lt;em&gt;INCORRECT!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;If you answered &lt;strong&gt;(B)&lt;/strong&gt;, you&amp;#x27;re...&lt;/p&gt;&lt;p&gt;...&lt;strong&gt;&lt;em&gt;CORRECT!&lt;/em&gt;&lt;/strong&gt; &lt;small&gt;sadly... 😢&lt;/small&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Surely you can&amp;#x27;t be serious.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0008-sort-it-out-js/images/surely.gif&quot; alt=&quot;I am serious and don&amp;#x27;t call me Shirley.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;I am serious and don&amp;#x27;t call me Shirley.&lt;/figcaption&gt;&lt;h2 id=&quot;the-problematic-code&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-problematic-code&quot; aria-label=&quot;the problematic code permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Problematic Code&lt;/h2&gt;&lt;p&gt;The reason why this bit me is that I initially wrote the code to &lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/blob/3105787df9d879252b198a5e719817b20c6c2b64/scripts/new-post/new-post-number.js&quot;&gt;calculate the &lt;em&gt;next&lt;/em&gt; prefix number&lt;/a&gt; using &lt;code class=&quot;language-text&quot;&gt;.sort()&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s the old way I wrote it:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;newPostNumber&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; postNumbers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; fs
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;readdirSync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;blogsPath&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// read the content/blog directory, like `ls`&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;filename&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;-&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// get the prefix, as a number&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Boolean&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// remove any falsey things, like things that don&amp;#x27;t match our pattern&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// sort the list in order&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// reverse the list so I can pick the first one (last number)&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// increment the last number used by one&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; postNumber &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; postNumbers&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// pad the post number with up to 3 zeros (4 number slots)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;postNumber&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;padStart&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;0&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Problematic code&lt;/figcaption&gt;&lt;blockquote&gt;&lt;p&gt;I used &lt;code class=&quot;language-text&quot;&gt;.sort()&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So, the list of &lt;strong&gt;&lt;em&gt;numbers&lt;/em&gt;&lt;/strong&gt; was converted to strings and then... well, you know the rest.
After &lt;code class=&quot;language-text&quot;&gt;&amp;quot;0009&amp;quot;&lt;/code&gt;, I would have been stuck generating &lt;code class=&quot;language-text&quot;&gt;&amp;quot;0010-...&amp;quot;&lt;/code&gt; directories! 😳&lt;/p&gt;&lt;h2 id=&quot;the-fix&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-fix&quot; aria-label=&quot;the fix permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Fix&lt;/h2&gt;&lt;p&gt;To fix the above code, all I needed to do was provide my own &lt;code class=&quot;language-text&quot;&gt;comparator&lt;/code&gt; function:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-diff line-numbers&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;- .sort()
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;+ .sort((lhs, rhs) =&amp;gt; lhs - rhs)&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Custom comparator function&lt;/figcaption&gt;&lt;p&gt;This comparator function returns true when the first argument is less than the second, forcing a swap between the two.
In other words, we&amp;#x27;re incrementing in ascending order, &lt;strong&gt;&lt;em&gt;what we originally wanted&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;newPostNumber&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; postNumbers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; fs
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;readdirSync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;blogsPath&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;filename&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;-&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Boolean&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;l&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; r&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; l &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; r&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; postNumber &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; postNumbers&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;postNumber&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;padStart&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;0&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;The working code using a custom comparator function.&lt;/figcaption&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Look, I get it.
It works for strings.
The default sorting algorithm is pretty generic.
But maybe that&amp;#x27;s the problem?&lt;/p&gt;&lt;p&gt;In the wise words of the Letterkenny gang:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;JavaScript, you figure it out.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0008-sort-it-out-js/images/figure-it-out.gif&quot; alt=&quot;Figure it out.&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Figure it out.&lt;/figcaption&gt;</content:encoded></item><item><title><![CDATA[Wild React 🦒: useForceUpdate()]]></title><description><![CDATA[Y'all wanna see something wild? 🦒👀 A little known method There is a method in the React component class API that is fairly unknown and…]]></description><link>https://codyaprice.com/blog/yall-wanna-see-something-wild/</link><guid isPermaLink="false">https://codyaprice.com/blog/yall-wanna-see-something-wild/</guid><pubDate>Wed, 30 Oct 2019 04:14:10 GMT</pubDate><content:encoded>&lt;p&gt;Y&amp;#x27;all wanna see something wild? 🦒👀&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;a-little-known-method&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#a-little-known-method&quot; aria-label=&quot;a little known method permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A little known method&lt;/h2&gt;&lt;p&gt;There is a method in the React component class API that is fairly unknown and rarely used: &lt;a href=&quot;https://reactjs.org/docs/react-component.html#forceupdate&quot;&gt;forceUpdate()&lt;/a&gt;.
As the React docs state,&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;By default, when your component’s state or props change, your component will re-render.
If your &lt;code class=&quot;language-text&quot;&gt;render()&lt;/code&gt; method depends on some other data, you can tell React that the component needs re-rendering by calling &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In a normal React application, changes to &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;state&lt;/code&gt;, and even &lt;code class=&quot;language-text&quot;&gt;context&lt;/code&gt; is the main driver of component render cycles.
However, you &lt;strong&gt;&lt;em&gt;can&lt;/em&gt;&lt;/strong&gt; tell React to re-render your component without updating any of those things.
And one special way to do that is to call &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s take a glance at what this may look like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;BadExample&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;callJGWentworth&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// call J.G. Wentworth, or just tell React we need it now 👇&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;877-CASH-NOW!!!&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;I have a structured settlement&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;callJGWentworth&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          AND I NEED CASH NOW
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;React component forceUpdate() example usage&lt;/figcaption&gt;&lt;p&gt;Yeah, I know the code is bad, but it&amp;#x27;s only &lt;del&gt;a reflection of my daily code production&lt;/del&gt; &lt;em&gt;an example&lt;/em&gt;.
&lt;strong&gt;&lt;em&gt;It actually doesn&amp;#x27;t do anything.&lt;/em&gt;&lt;/strong&gt; &lt;small&gt;&lt;em&gt;&lt;strong&gt;kinda&lt;/strong&gt;&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0007-yall-wanna-see-something-wild/images/be-a-lot-cooler.png&quot; alt=&quot;Be a lot cooler if it did&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Be a lot cooler if it did&lt;/figcaption&gt;&lt;p&gt;Here&amp;#x27;s what running the above code looks like:&lt;/p&gt;&lt;style data-emotion-css=&quot;asrzgk&quot;&gt;.css-asrzgk{text-align:center;padding:0.5rem;border:0.25rm dashed;}&lt;/style&gt;&lt;div class=&quot;css-asrzgk&quot;&gt;&lt;h2&gt;I have a structured settlement&lt;/h2&gt;&lt;button type=&quot;button&quot;&gt;AND I NEED CASH NOW&lt;/button&gt;&lt;/div&gt;&lt;br/&gt;&lt;figcaption&gt;🎶 877-CASH-NOW!!! 🎶&lt;/figcaption&gt;&lt;p&gt;One thing to be aware of is that &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; will skip &lt;code class=&quot;language-text&quot;&gt;shouldComponentUpdate()&lt;/code&gt; (which by default just &lt;a href=&quot;https://github.com/facebook/react/blob/1022ee0ec140b8fce47c43ec57ee4a9f80f42eca/packages/react-reconciler/src/ReactFiberClassComponent.js#L292&quot;&gt;returns true&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;Going back to the React docs:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Calling &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; will cause &lt;code class=&quot;language-text&quot;&gt;render()&lt;/code&gt; to be called on the component, skipping &lt;code class=&quot;language-text&quot;&gt;shouldComponentUpdate()&lt;/code&gt;.
This will trigger the normal lifecycle methods for child components, including the &lt;code class=&quot;language-text&quot;&gt;shouldComponentUpdate()&lt;/code&gt; method of each child.
&lt;strong&gt;React will still only update the DOM if the markup changes.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;That last sentence simply means that calling &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; could end up being a &lt;code class=&quot;language-text&quot;&gt;no-op&lt;/code&gt; function, e.g. &lt;code class=&quot;language-text&quot;&gt;() =&amp;gt; {}&lt;/code&gt;.
If nothing in the DOM will change by forcing a re-render, then you&amp;#x27;ve done some wasted work on the UI thread.
&lt;a href=&quot;https://dassur.ma/things/when-workers/&quot;&gt;And we don&amp;#x27;t want that.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Use&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; &lt;strong&gt;&lt;em&gt;sparingly and with intention.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;forceupdate-the-react-hooks-hway&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#forceupdate-the-react-hooks-hway&quot; aria-label=&quot;forceupdate the react hooks hway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;forceUpdate(), the React hooks hway&lt;/h2&gt;&lt;p&gt;If you&amp;#x27;ve used React &lt;a href=&quot;https://reactjs.org/docs/hooks-intro.html&quot;&gt;hooks&lt;/a&gt;, you&amp;#x27;ve probably noticed that:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;They&amp;#x27;re awesome 😎&lt;/li&gt;&lt;li&gt;They don&amp;#x27;t have a hook corollary to &lt;a href=&quot;https://reactjs.org/docs/react-component.html#componentdidcatch&quot;&gt;componentDidCatch&lt;/a&gt; or forceUpdate() (&lt;em&gt;hey, what gives??&lt;/em&gt;)&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Alright, well maybe you &lt;strong&gt;&lt;em&gt;haven&amp;#x27;t&lt;/em&gt;&lt;/strong&gt; noticed point #2.
That&amp;#x27;s &lt;em&gt;alright, alright, alright&lt;/em&gt;.&lt;/p&gt;&lt;p&gt;It may not exist as a first class hook, but that can&amp;#x27;t stop us!
Let&amp;#x27;s write a custom hook!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useForceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; forceUpdate&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;forceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;s&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;forceUpdate(), but as a hook: useForceUpdate()&lt;/figcaption&gt;&lt;h3 id=&quot;so-what-does-this-hook-do&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#so-what-does-this-hook-do&quot; aria-label=&quot;so what does this hook do permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;So, what does this hook do?&lt;/h3&gt;&lt;p&gt;Well, it first calls &lt;code class=&quot;language-text&quot;&gt;React.useState()&lt;/code&gt; and passes nothing, or &lt;code class=&quot;language-text&quot;&gt;undefined&lt;/code&gt;, to the initial state.
Notice however, that it doesn&amp;#x27;t care about the first argument returned in the &lt;code class=&quot;language-text&quot;&gt;useState()&lt;/code&gt; tuple, which is the &lt;strong&gt;&lt;em&gt;state variable&lt;/em&gt;&lt;/strong&gt;.
We will soon see that this is okay though, because our initial state is &lt;code class=&quot;language-text&quot;&gt;falsey&lt;/code&gt;, which is just a funny way of saying that it evaluates to &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;.
It&amp;#x27;s important to note that we&amp;#x27;ve effectively made the state variable &lt;strong&gt;&lt;em&gt;private&lt;/em&gt;&lt;/strong&gt; to the custom hook, or &lt;strong&gt;&lt;em&gt;hidden&lt;/em&gt;&lt;/strong&gt; to the outside users.
The state variable still exists, but &lt;em&gt;we just don&amp;#x27;t expose it for use&lt;/em&gt;.
Here&amp;#x27;s what happens in &lt;a href=&quot;https://github.com/facebook/react/tree/master/packages/react-devtools-extensions#installation&quot;&gt;React DevTools&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0007-yall-wanna-see-something-wild/images/useForceUpdate-in-react-devtools.gif&quot; alt=&quot;useForceUpdate in React DevTools ⚛️&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;useForceUpdate() in React DevTools ⚛️&lt;/figcaption&gt;&lt;p&gt;The last thing that the &lt;code class=&quot;language-text&quot;&gt;useForceUpdate&lt;/code&gt; hook does is return a memoized callback that simply toggles the unnamed state variable.
Just like in the React class component method &lt;a href=&quot;https://reactjs.org/docs/react-component.html#setstate&quot;&gt;setState&lt;/a&gt;, you can pass an &lt;em&gt;updater function&lt;/em&gt; to the &lt;code class=&quot;language-text&quot;&gt;React.useState()&lt;/code&gt; setter, as I&amp;#x27;ve done here.
This updater function just happens to return the inverse of what the unnamed state variable currently is, e.g. &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; ➡️ &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re unsure about what I mean by &lt;strong&gt;&lt;em&gt;&amp;quot;memoized callback&amp;quot;&lt;/em&gt;&lt;/strong&gt;, that&amp;#x27;s okay.
In this case, we just want the function &lt;code class=&quot;language-text&quot;&gt;() =&amp;gt; { forceUpdate(); }&lt;/code&gt; to always refer to the same underlying object reference.
So, we&amp;#x27;re caching, or remembering, what the function is, even across separate calls to &lt;code class=&quot;language-text&quot;&gt;useForceUpdate&lt;/code&gt;.
If you&amp;#x27;re curious for more info on memoization, check out this &lt;a href=&quot;https://en.wikipedia.org/wiki/Memoization&quot;&gt;Wikipedia article&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;To answer the question &lt;strong&gt;&lt;em&gt;&amp;quot;What does this hook do?&amp;quot;&lt;/em&gt;&lt;/strong&gt;, it allows you to force a re-render in your functional component without actually changing &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;state&lt;/code&gt;, or &lt;code class=&quot;language-text&quot;&gt;context&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;I have misled you a bit, however.
The &lt;code class=&quot;language-text&quot;&gt;useForceUpdate()&lt;/code&gt; hook isn&amp;#x27;t quite a 1-to-1 comparison with the &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; class component usage above.
That&amp;#x27;s because there&amp;#x27;s no &lt;a href=&quot;https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-shouldcomponentupdate&quot;&gt;shouldComponentUpdate() hook&lt;/a&gt;.
Hooks require a &lt;strong&gt;&lt;em&gt;different&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://kentcdodds.com/chats-with-kent-podcast/seasons/01/episodes/realigning-your-model-of-react-after-hooks-with-dan-abramov&quot;&gt;mental model of React&lt;/a&gt;.&lt;/p&gt;&lt;h2 id=&quot;example-time-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#example-time-&quot; aria-label=&quot;example time  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Example Time! ⏰&lt;/h2&gt;&lt;p&gt;Here&amp;#x27;s the part I&amp;#x27;ve been wanting to show you.
But, before I reveal the code we will be running, I want to talk about a couple of things.&lt;/p&gt;&lt;p&gt;First, let&amp;#x27;s touch back on what causes a React component to re-render.
As I mentioned before, a component will re-render if:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;its &lt;code class=&quot;language-text&quot;&gt;shouldComponentUpdate()&lt;/code&gt; returns &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;&lt;/li&gt;&lt;li&gt;its own internal state changes&lt;/li&gt;&lt;li&gt;it receives new props&lt;/li&gt;&lt;li&gt;the context it hooks into changes&lt;/li&gt;&lt;li&gt;it&amp;#x27;s a class component that calls &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Notice that changing React &lt;a href=&quot;https://reactjs.org/docs/refs-and-the-dom.html&quot;&gt;refs&lt;/a&gt; don&amp;#x27;t cause a re-render.
Refs are nice for imperatively mutating DOM nodes.
I primarily use them for focus management: &lt;code class=&quot;language-text&quot;&gt;ref.current.focus()&lt;/code&gt;.
But, you can also use them to store instance-like-variables, even in functional components!
Keep in mind that changing these kinds of instance-like-variables &lt;strong&gt;&lt;em&gt;won&amp;#x27;t trigger a re-render&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Next, I wanna briefly talk about one of my favorite hooks: &lt;code class=&quot;language-text&quot;&gt;React.useEffect()&lt;/code&gt;.
And by briefly talk about, I really just mean referencing a tweet from &lt;a href=&quot;https://twitter.com/ryanflorence&quot;&gt;@ryanflorence&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;A quick and helpful guide on &lt;code class=&quot;language-text&quot;&gt;React.useEffect()&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0007-yall-wanna-see-something-wild/images/ryan-florence-use-effect.png&quot; alt=&quot;Ryan Florence on Twitter: &amp;quot;@dan_abramov @_developit @mjackson The question is not &amp;quot;when does this effect run&amp;quot; the question is &amp;quot;with which state does this effect synchronize with&amp;quot; useEffect(fn) // all state useEffect(fn, []) // no state useEffect(fn, [these, states])&amp;quot;&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Tweet: &lt;a href=&quot;https://twitter.com/ryanflorence/status/1125041041063665666?lang=en&quot;&gt;Ryan Florence (@ryanflorence) May 5, 2019&lt;/a&gt;&lt;/figcaption&gt;&lt;p&gt;Now that that&amp;#x27;s out of the way, let&amp;#x27;s see some code, Cody! 🤓&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;UseTheForce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; forceUpdate &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useForceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; renderCount &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useRef&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    renderCount&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;current &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; onClick &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;forceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;forceUpdate&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;onClick&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        Use the Force 👋
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Render count: &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;renderCount&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;current&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And here it is, running &lt;kbd&gt;(((wild)))&lt;/kbd&gt;.
Go ahead, give it a click. 👇&lt;/p&gt;&lt;style data-emotion-css=&quot;1pb8dvd&quot;&gt;.css-1pb8dvd{text-align:center;padding:0.5rem;border:0.25rem dashed;}&lt;/style&gt;&lt;div class=&quot;css-1pb8dvd&quot;&gt;&lt;button type=&quot;button&quot;&gt;Use the Force &lt;span role=&quot;img&quot; aria-label=&quot;wave emoji&quot;&gt;👋&lt;/span&gt;&lt;/button&gt;&lt;div&gt;Render count: 0&lt;/div&gt;&lt;/div&gt;&lt;br/&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0007-yall-wanna-see-something-wild/images/well-there-it-is.gif&quot; alt=&quot;Well there it is&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Well there it is&lt;/figcaption&gt;&lt;p&gt;The oddball &lt;code class=&quot;language-text&quot;&gt;UseTheForce&lt;/code&gt; component, rendered in all its glory.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0007-yall-wanna-see-something-wild/images/how-neat-is-that.gif&quot; alt=&quot;How neat is that? 🌲&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;How neat is that? 🌲&lt;/figcaption&gt;&lt;h2 id=&quot;lets-break-it-down-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#lets-break-it-down-&quot; aria-label=&quot;lets break it down  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Let&amp;#x27;s break it down 💃&lt;/h2&gt;&lt;p&gt;First, we get our &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; callback:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// get the forceUpdate() callback by calling the useForceUpdate() hook&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; forceUpdate &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useForceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Get the forceUpdate() callback by calling the useForceUpdate() hook&lt;/figcaption&gt;&lt;p&gt;Now, let&amp;#x27;s grab a &lt;code class=&quot;language-text&quot;&gt;ref&lt;/code&gt; to a &lt;em&gt;pseudo-instance-variable&lt;/em&gt; counter, initialized to &lt;code class=&quot;language-text&quot;&gt;0&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// let&amp;#x27;s retain some counting state without useState()... with refs!&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// initialize the ref.current value to 0&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; renderCount &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useRef&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Use state without useState(), ya dig?&lt;/figcaption&gt;&lt;p&gt;Using our handy dandy &lt;del&gt;notebook 📕&lt;/del&gt; &lt;code class=&quot;language-text&quot;&gt;React.useEffect()&lt;/code&gt; guide from Ryan Florence, let&amp;#x27;s increment the counter &lt;strong&gt;&lt;em&gt;on each render&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// add one to the render count ref&amp;#x27;s current value on each render&lt;/span&gt;
React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  renderCount&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;current &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// don&amp;#x27;t pass any dependency array here, not even empty list []&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Add one to the render count ref&amp;#x27;s current value on each render&lt;/figcaption&gt;&lt;p&gt;A simple click handler is necessary for the &lt;code class=&quot;language-text&quot;&gt;&amp;lt;button&amp;gt;&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// When I click, you... don&amp;#x27;t click, just force the update!&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; onClick &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;useCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;forceUpdate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;forceUpdate&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Force an update when we click the button&lt;/figcaption&gt;&lt;p&gt;And finally, &lt;del&gt;draw the rest of the ****ing owl&lt;/del&gt; the markup:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-jsx line-numbers&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// render the button and our &amp;quot;state variable&amp;quot; render count&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;onClick&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      Use the Force 👋
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Render count: &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;renderCount&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;current&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;The example markup&lt;/figcaption&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; Don&amp;#x27;t do this.&lt;sup&gt;*&lt;/sup&gt;&lt;/p&gt;&lt;p&gt;This was definitely an exercise in &lt;em&gt;what if?&lt;/em&gt; territory.
While there are certainly &lt;a href=&quot;https://github.com/alphagov/accessible-autocomplete/blob/4bebed4a4799b39ee1cd493336988bafb53aa0ef/src/autocomplete.js#L302&quot;&gt;use cases&lt;/a&gt; for &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt;, odds are you&amp;#x27;re better off using hooks, &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;state&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;context&lt;/code&gt; to declaratively render what you want and when.&lt;/p&gt;&lt;p&gt;If nothing in the DOM will change by forcing a re-render, then you&amp;#x27;ve done some wasted work on the UI thread.
The UI thread is a precious resource and we should be using it as little as possible for maximum performance.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Again, use&lt;/em&gt;&lt;/strong&gt; &lt;code class=&quot;language-text&quot;&gt;forceUpdate()&lt;/code&gt; &lt;strong&gt;&lt;em&gt;sparingly and with intention.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;And if you&amp;#x27;re thinking about reaching for something like the custom &lt;code class=&quot;language-text&quot;&gt;useForceUpdate()&lt;/code&gt; hook above, then you&amp;#x27;re probably &lt;a href=&quot;https://www.engadget.com/2010/06/24/apple-responds-over-iphone-4-reception-issues-youre-holding-th/&quot;&gt;holding it wrong&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Thanks for coming to my TED talk. After all, &lt;a href=&quot;https://twitter.com/dan_abramov/status/1120987501072650240&quot;&gt;all the cool kids are doing it&lt;/a&gt;.&lt;/p&gt;&lt;sup&gt;\*&lt;/sup&gt;&lt;small&gt;Unless you have &lt;em&gt;&lt;strong&gt;good reason&lt;/strong&gt;&lt;/em&gt; to. &lt;s&gt;Terms and conditions&lt;/s&gt; Nuance applies.&lt;/small&gt;</content:encoded></item><item><title><![CDATA[Update: Event Loop Article is coming]]></title><description><![CDATA[Update: I have a working MDX configuration on a feature branch!
Interactive examples are coming! 💪💪💪 Example: React Component Embedded in…]]></description><link>https://codyaprice.com/blog/update-on-event-loop-article/</link><guid isPermaLink="false">https://codyaprice.com/blog/update-on-event-loop-article/</guid><pubDate>Thu, 17 Oct 2019 16:51:49 GMT</pubDate><content:encoded>&lt;blockquote&gt;&lt;p&gt;Update: I have a working MDX configuration on a feature branch!
Interactive examples are coming! 💪💪💪&lt;/p&gt;&lt;/blockquote&gt;&lt;h2 id=&quot;example-react-component-embedded-in-markdown&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#example-react-component-embedded-in-markdown&quot; aria-label=&quot;example react component embedded in markdown permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Example: React Component Embedded in Markdown&lt;/h2&gt;&lt;style data-emotion-css=&quot;zepm5v&quot;&gt;.css-zepm5v{border:0.25rem #c0c0c0 dashed;margin:1rem 0;padding:1rem;}&lt;/style&gt;&lt;div class=&quot;css-zepm5v&quot;&gt;&lt;h1&gt;React Counter Component&lt;/h1&gt;&lt;h2&gt;Count: 0&lt;/h2&gt;&lt;style data-emotion-css=&quot;5016st&quot;&gt;.css-5016st{display:block;width:40%;margin:auto;}&lt;/style&gt;&lt;button type=&quot;button&quot; class=&quot;css-5016st&quot;&gt;+&lt;/button&gt;&lt;style data-emotion-css=&quot;v0p116&quot;&gt;.css-v0p116{display:block;width:40%;margin:auto;margin-bottom:1rem;}&lt;/style&gt;&lt;button type=&quot;button&quot; class=&quot;css-v0p116&quot;&gt;-&lt;/button&gt;&lt;small&gt;This is rendered inside markdown (using MDX!) &lt;span role=&quot;img&quot; aria-label=&quot;nerd face emoji&quot;&gt;🤓&lt;/span&gt;&lt;/small&gt;&lt;/div&gt;&lt;br/&gt;&lt;figcaption&gt;Turns out good content takes a lot of time and effort. Who knew? 🤷‍♂️ 😂&lt;/figcaption&gt;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; &lt;em&gt;It&amp;#x27;s coming...&lt;strong&gt;soon&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0006-update-on-event-loop-article/images/soon.gif&quot; alt=&quot;Soon... 🦉&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Soon... 🦉&lt;/figcaption&gt;&lt;p&gt;So what&amp;#x27;s the deal? Why didn&amp;#x27;t the article drop at 11am local time?
&lt;em&gt;&lt;strong&gt;It&amp;#x27;s Thursday after all&lt;/strong&gt;&lt;/em&gt;.
Well, I feel that in order to explain some of the more complicated topics it requires either animated or interactive elements.
A lot of concepts related to the JavaScript event loop are much easier to explain when you have more than simple, static content.&lt;/p&gt;&lt;h2 id=&quot;and-thats-what-i-want-to-provide&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#and-thats-what-i-want-to-provide&quot; aria-label=&quot;and thats what i want to provide permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;And that&amp;#x27;s what I want to provide.&lt;/h2&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0006-update-on-event-loop-article/images/excuses.gif&quot; alt=&quot;Excuses, excuses... 😒&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Excuses, excuses... 😒&lt;/figcaption&gt;&lt;p&gt;I want to have the ability to give you, the reader, an opportunity to really understand what is going on with each, transient step in the event loop workflow.
Things like describing a stack, queue, and what a specific function call did are much easier with dynamic content (animations and interactive content).&lt;/p&gt;&lt;h2 id=&quot;how-will-you-provide-interactive-content&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#how-will-you-provide-interactive-content&quot; aria-label=&quot;how will you provide interactive content permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How will you provide interactive content?&lt;/h2&gt;&lt;p&gt;First off, I &lt;em&gt;could&lt;/em&gt; rip off some prior art as gifs, but that seems wrong.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Good artists copy; Great artists steal&lt;/p&gt;&lt;p&gt;Pablo Piscasso&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Also, I&amp;#x27;m rusty on my digital art, so making my own gifs or videos seems really time consuming.
Instead, I&amp;#x27;ll be making React components which I&amp;#x27;ll be able to embed directly into the article&amp;#x27;s page.
&lt;em&gt;And &lt;strong&gt;you&lt;/strong&gt; will be able to play with them!&lt;/em&gt;&lt;/p&gt;&lt;h2 id=&quot;neat-right&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#neat-right&quot; aria-label=&quot;neat right permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Neat, right?&lt;/h2&gt;&lt;p&gt;Well, I think so! 🌝
And that&amp;#x27;s what&amp;#x27;s taking so long.
I have all the content I want to write.
I know what I want to say and how I want to say it.
However, I don&amp;#x27;t want you to get lost in the nuance of the details.&lt;/p&gt;&lt;h2 id=&quot;it-can-and-may-get-highly-technical&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#it-can-and-may-get-highly-technical&quot; aria-label=&quot;it can and may get highly technical permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;It can and may get highly technical&lt;/h2&gt;&lt;p&gt;And when it does, my weapon for clarity and against glazed over 👀 is &lt;em&gt;interactivity&lt;/em&gt;.
I just need to make some website configuration changes to allow for embedding this kind of content.&lt;/p&gt;&lt;p&gt;So, while I may have missed the mark this week, it&amp;#x27;ll be ready next week.&lt;/p&gt;&lt;h2 id=&quot;i-promise-🤞&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#i-promise-%F0%9F%A4%9E&quot; aria-label=&quot;i promise 🤞 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;I promise. 🤞&lt;/h2&gt;</content:encoded></item><item><title><![CDATA[git commit -m "write more"]]></title><description><![CDATA[It's about time. ⏳
At least, it's about the commitment to stick to a certain time.
 And I'll keep this post short and quick . TLDR : I have…]]></description><link>https://codyaprice.com/blog/git-commit-m-write-more/</link><guid isPermaLink="false">https://codyaprice.com/blog/git-commit-m-write-more/</guid><pubDate>Tue, 15 Oct 2019 23:27:33 GMT</pubDate><content:encoded>&lt;p&gt;It&amp;#x27;s about time. ⏳
At least, it&amp;#x27;s about the commitment to stick to a certain time.
&lt;em&gt;And I&amp;#x27;ll keep this post short and quick&lt;/em&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;: I have a Public Accountability Statement.
I&amp;#x27;m officially committing to writing a new article every week and posting on Thursday at noon local time, starting this week.
And let&amp;#x27;s be real, this post is short enough that a TLDR wasn&amp;#x27;t really necessary, but here we are 🙃.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;I haven&amp;#x27;t written anything new for the past (nearly) two months.
Even though my backlog of blog post thoughts, insights, and ideas continues to grow daily (around 30 items strong now).
It&amp;#x27;s kinda starting to look like my JIRA backlog at work 😅.&lt;/p&gt;&lt;p&gt;I&amp;#x27;ve already posted about this on the socials, but it&amp;#x27;s time for action.
So, in my attempt to get a head start on abandoning my New Year&amp;#x27;s resolutions, I&amp;#x27;m going to begin a few now.
A major one, which happens to be the reason for this particular post, is to write more and consistently.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Teach us to number our days, that we may gain a heart of wisdom.
Psalm 90:12&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So, I&amp;#x27;m numbering my days and committing to writing at least one article per week and publishing it on Thursdays at noon.
My first entry will be a big and exciting one: the JavaScript event loop.&lt;/p&gt;&lt;p&gt;I&amp;#x27;m not going to constrain myself to write a set amount, just that I do write.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Electrical Reflections: What he learned will SHOCK you!!!]]></title><description><![CDATA[Currently reflecting on how thankful I am for all the opportunities I've been blessed with.
Specifically, the ability to recognize subpar…]]></description><link>https://codyaprice.com/blog/electrical-safety/</link><guid isPermaLink="false">https://codyaprice.com/blog/electrical-safety/</guid><pubDate>Fri, 11 Oct 2019 11:19:00 GMT</pubDate><content:encoded>&lt;p&gt;Currently reflecting on how thankful I am for all the opportunities I&amp;#x27;ve been blessed with.
Specifically, the ability to recognize subpar electrical work and the capability to fix it for the safety of my family.&lt;/p&gt;&lt;p&gt;I was reading up on electrical subpanels on my lunch break since our home has one in the basement.&lt;/p&gt;&lt;h2 id=&quot;what-i-learned-will-shock-you&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#what-i-learned-will-shock-you&quot; aria-label=&quot;what i learned will shock you permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;WHAT I LEARNED WILL SHOCK YOU!!!&lt;/h2&gt;&lt;p&gt;With what I learned, well just call me shocked (pun intended ⚡️) that we haven&amp;#x27;t had an &lt;em&gt;unfortunate incident&lt;/em&gt; ☠️.
Such an incident where, as someone online so eloquently put:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;quot;All it takes is a preexisting fault, one rainstorm, or wet feet, whatever... and you touching something energized - and you&amp;#x27;re doing the 60 cycle shuffle.&amp;quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Arcing. Electrocution. &lt;strong&gt;&lt;em&gt;Bad shocky things.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;h2 id=&quot;what-is-an-electricians-favorite-flavor-of-ice-cream-shock-a-lot&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#what-is-an-electricians-favorite-flavor-of-ice-cream-shock-a-lot&quot; aria-label=&quot;what is an electricians favorite flavor of ice cream shock a lot permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is an electrician&amp;#x27;s favorite flavor of ice cream? Shock-a-lot.&lt;/h2&gt;&lt;p&gt;⚡️️️️️️️️️⚡️⚡️&lt;/p&gt;&lt;p&gt;I&amp;#x27;ve been shocked (embarrassingly, multiple times) from being careless around my main panel.
It&amp;#x27;s not fun.&lt;/p&gt;&lt;p&gt;Our home&amp;#x27;s basement, an ill-planned afterthought-addition, prefers to remain wet.
This is primarily because of two things.&lt;/p&gt;&lt;p&gt;First, the basement was added after the home was built.
So, they dug out from beneath it and used regular old concrete cinder blocks for the foundation walls.&lt;/p&gt;&lt;p&gt;Second, surprisingly, concrete is a rather porous material and water loves to penetrate it.
And when this happens, it can build up a lot of pressure which forces the water into places that it doesn&amp;#x27;t belong, like a basement.&lt;/p&gt;&lt;h2 id=&quot;hence-our-wet-basement&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#hence-our-wet-basement&quot; aria-label=&quot;hence our wet basement permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Hence, our wet basement.&lt;/h2&gt;&lt;p&gt;Our basement&amp;#x27;s electrical subpanel is definitely not wired correctly.
Oh and there definitely exists a potential parallel path for ground currents.
Don&amp;#x27;t even get me started on how a 30 amp breaker is supplying 3 15s and a single 20.&lt;/p&gt;&lt;p&gt;First off, I have about 5 or 6 open slots on my main panel, so this subpanel is completely unnecessary.
Second, that 30A breaker is connected to 4 or 5 outlets, a separate half bath attached to the living room (lol, right?), and the air conditioning.
😒
This breaker solely exists to bring power to the AC, yet it has all these extra, unsafe connections/additions.&lt;/p&gt;&lt;h2 id=&quot;whats-the-definition-of-a-shock-absorber-a-careless-electrician&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#whats-the-definition-of-a-shock-absorber-a-careless-electrician&quot; aria-label=&quot;whats the definition of a shock absorber a careless electrician permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What&amp;#x27;s the definition of a shock absorber? A careless electrician.&lt;/h2&gt;&lt;p&gt;The state of all this makes me angry and scared.
I&amp;#x27;m scared for those who&amp;#x27;ve inherited such an unsafe mess as we have.
How many other homes exist with similar, or worse, electrical work?&lt;/p&gt;&lt;p&gt;This fault exists because of multiple people along the &lt;em&gt;chain-of-command&lt;/em&gt;, so to speak, who were either unqualified, negligent, or more likely both who wired up the home.
And unfortunately, it can be really expensive to fix faults as time goes on.
Most likely, it involves running new line, disposing of and installing new drywall, and maybe even framing work.
So, even if you can recognize such failures, you may not have the resources available to fix them.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s be clear: I&amp;#x27;m &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; a licensed electrician.
I&amp;#x27;m just an engineer with a thirst for knowledge and doing what&amp;#x27;s right.
However, thankfully I took enough electrical engineering courses to be dangerous (and earn a degree).
I have also had the opportunity to shadow those more qualified than me as a contractor during the summers between semesters.
Lives are at stake here.
Electricity is &lt;strong&gt;dangerous&lt;/strong&gt;.&lt;/p&gt;&lt;h2 id=&quot;we-have-to-do-better&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#we-have-to-do-better&quot; aria-label=&quot;we have to do better permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;We have to do better.&lt;/em&gt;&lt;/h2&gt;</content:encoded></item><item><title><![CDATA[The Best Practice is Shipping]]></title><description><![CDATA[TLDR:  I'm pivoting. I've always wanted to have my own lil' corner on the web. A spot to show off my
accomplishments and projects, share…]]></description><link>https://codyaprice.com/blog/the-best-practice-is-shipping/</link><guid isPermaLink="false">https://codyaprice.com/blog/the-best-practice-is-shipping/</guid><pubDate>Thu, 22 Aug 2019 05:56:08 GMT</pubDate><content:encoded>&lt;hr/&gt;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; I&amp;#x27;m pivoting.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/which-one.gif&quot; alt=&quot;Which framework? Which one?&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;I&amp;#x27;m pivoting to a new framework. Which one? Which one?&lt;/figcaption&gt;&lt;p&gt;I&amp;#x27;ve always wanted to have my own lil&amp;#x27; corner on the web. A spot to show off my
accomplishments and projects, share knowledge and insights, occasionally blog,
and house my portfolio. About two weeks ago, August 8th to be exact, I pulled the
trigger and bought my domain, &lt;a href=&quot;https://codyaprice.com&quot;&gt;codyaprice.com&lt;/a&gt;, from
&lt;a href=&quot;https://domains.google.com&quot;&gt;Google Domains&lt;/a&gt;. After that, I needed a way to
deploy it. I had heard great things about &lt;a href=&quot;https://zeit.co&quot;&gt;zeit&lt;/a&gt; and gave them
a shot (can&amp;#x27;t recommend them enough btw!). So, within fifteen minutes and twelve
dollars later, I had a domain and deployment/cdn service. Awesome!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/now-what.gif&quot; alt=&quot;Now what?&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;I have a domain.. now what?&lt;/figcaption&gt;&lt;h2 id=&quot;get-framework&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#get-framework&quot; aria-label=&quot;get framework permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;GET /framework&lt;/h2&gt;&lt;p&gt;A few weeks before I got my itchy trigger finger, I found
&lt;a href=&quot;https://twitter.com/Rich_Harris&quot;&gt;@Rich_Harris&amp;#x27;&lt;/a&gt; talk about
&lt;a href=&quot;https://youtu.be/AdNJ3fydeao&quot;&gt;rethinking reactivity&lt;/a&gt; and fell in love with
&lt;a href=&quot;https://svelte.dev&quot;&gt;svelte&lt;/a&gt;. This is what a UI framework should be!&lt;/p&gt;&lt;p&gt;Don&amp;#x27;t get me wrong, I love React. I love how easy it is to create beautiful and
flexible interfaces with a declarative, straightforward approach. I love working
with ES2015+ JavaScript and it has somehow become the language I &lt;em&gt;think&lt;/em&gt; in. My
pseudocode is pretty much JS now. However, it&amp;#x27;s always bothered me that you have
to include &lt;em&gt;&lt;strong&gt;the universe&lt;/strong&gt;&lt;/em&gt; with any React app, while
&lt;a href=&quot;https://reactjs.org/docs/reconciliation.html&quot;&gt;reconciliation&lt;/a&gt; and the virtual
DOM
&lt;a href=&quot;https://medium.com/@hayavuk/why-virtual-dom-is-slower-2d9b964b4c9e&quot;&gt;ain&amp;#x27;t free&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/node-modules.png&quot; alt=&quot;node_modules... oof&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Just give it another `rm -rf` for good measure.&lt;/figcaption&gt;&lt;blockquote&gt;&lt;p&gt;React needs to figure out how to efficiently update the UI to match the most
recent tree...[and] implements a heuristic &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; algorithm.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The virtual DOM is
&lt;a href=&quot;https://svelte.dev/blog/virtual-dom-is-pure-overhead&quot;&gt;pure overhead&lt;/a&gt;!
Reconciliation is at least &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; and runs on each render cycle. It&amp;#x27;s true
that, in general, React apps can consistently output 60 fps, but surely we can
do better than &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; on top of what the browser already does and giant chunks
of JavaScript runtime right?&lt;/p&gt;&lt;p&gt;So back to svelte. What drew me to svelte was that it is component based, not
unlike React, and compiled to &lt;em&gt;just JavaScript&lt;/em&gt; without polluting your bundle
with production dependencies. It builds fast, ships fast, and runs fast. It&amp;#x27;s
got a beautiful API and is performant enough to run on
&lt;a href=&quot;https://twitter.com/sveltejs/status/1088500539640418304&quot;&gt;embedded devices&lt;/a&gt;!&lt;/p&gt;&lt;p&gt;That&amp;#x27;s incredible. I mean, I went to school for Electrical and Computer
Engineering and cut my programming teeth on C and microcontrollers. Before
becoming a full time web developer, I was an Embedded Systems Engineer who
worked on extremely memory-and-power-constrained microprocessors. Some of them
had 32kB of memory, operated at 32MHz on a good day, and didn&amp;#x27;t even have a
heap! We did everything on the stack 📚! So, with that background, I can
confidently say that by definition, I&amp;#x27;m a perf nerd 🤓.&lt;/p&gt;&lt;p&gt;I was sold enough on svelte to use zeit&amp;#x27;s &lt;a href=&quot;https://sapper.svelte.dev/&quot;&gt;sapper&lt;/a&gt;
template. At least at first.&lt;/p&gt;&lt;h2 id=&quot;float-like-a-rock-sting-like-a-fly&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#float-like-a-rock-sting-like-a-fly&quot; aria-label=&quot;float like a rock sting like a fly permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Float Like a Rock, Sting Like a Fly&lt;/h2&gt;&lt;p&gt;As I&amp;#x27;ve said before, I basically live and breathe React. I write it M-F 9-5
&lt;a href=&quot;https://twitter.com/cernereng&quot;&gt;@cerner&lt;/a&gt;. So, transitioning to svelte was slow.
Even though it&amp;#x27;s similar to React and has a similar development &lt;em&gt;mouthfeel&lt;/em&gt;,
it&amp;#x27;s still &lt;em&gt;&lt;strong&gt;different&lt;/strong&gt;&lt;/em&gt;. There&amp;#x27;s a small learning curve and there&amp;#x27;s not
nearly as much community support (yet). This isn&amp;#x27;t svelte&amp;#x27;s fault, but it plays
a factor in how fast I can iterate on features and development for my website.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/elf-mouthfeel.png&quot; alt=&quot;elf on the shelf on Twitter: &amp;quot;Why is nobody talking about the mouth feel&amp;quot;&quot;/&gt;&lt;/p&gt;&lt;figcaption class=&quot;tweet&quot;&gt;Why aren&amp;#x27;t we talking about the mouthfeel, y&amp;#x27;all? 🤔&lt;/figcaption&gt;&lt;p&gt;At the beginning of this post, I mentioned what I want my website to contain:
blog posts, tutorials and knowledge sharing, projects, portfolio, content, etc.
Blog posts are great to pad websites with when fresh. Generally, they&amp;#x27;re just
text and images. Simple content. Being that I write a lot of documentation in
markdown, I wanted to be able to write my posts in markdown and then have a
build time pipeline that renders them to markdown. I also wanted syntax
highlighting for code snippets, since a lot of what I have to share is
code-centric. So, I found
&lt;a href=&quot;https://prismjs.com/&quot;&gt;prism&lt;/a&gt;
for syntax highlighting and
&lt;a href=&quot;https://unifiedjs.com/&quot;&gt;unified&lt;/a&gt;
for markdown to html parsing and conversion (and so much more). Both of these
tools are incredible, but there isn&amp;#x27;t a first class solution or plugin for
sapper. And I fought with getting prism to work properly with svelte since
&lt;a href=&quot;https://github.com/css-modules/css-modules&quot;&gt;css modules&lt;/a&gt;
are a first class feature and on by default (one of the things I love about
svelte). I worked on this in my spare time for nearly two weeks without
producing nor hosting any meaningful content.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/naked-svelte-website.png&quot; alt=&quot;naked website&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;My website was dormant, vacant, and quite naked. 🙈&lt;/figcaption&gt;&lt;p&gt;I was getting kind of frustrated and felt like I wasn&amp;#x27;t moving fast enough. I
just wanted to start with my
&lt;a href=&quot;https://medium.com/@dev.cprice&quot;&gt;medium articles&lt;/a&gt;
and go from there. I needed some help and perhaps some guidance. When I woke up
yesterday around 6am, I opened twitter on my phone and at the top of my feed was
a &lt;a href=&quot;https://twitter.com/ken_wheeler&quot;&gt;@ken_wheeler&lt;/a&gt; tweet:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/ken-best-practice-is-shipping.png&quot; alt=&quot;Ken Wheeler on Twitter: &amp;quot;@rickhanlonii The best practice is shipping&amp;quot;&quot;/&gt;&lt;/p&gt;&lt;figcaption class=&quot;tweet&quot;&gt;Ken Wheeler spittin&amp;#x27; facts: Best practice === ship it&lt;/figcaption&gt;&lt;p&gt;And that&amp;#x27;s when I decided I needed to move on from svelte and sapper.&lt;/p&gt;&lt;h2 id=&quot;great-gatsby&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#great-gatsby&quot; aria-label=&quot;great gatsby permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Great Gatsby&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;“And so with the sunshine and the great bursts of leaves growing on the trees,
just as things grow in fast movies, I had that familiar conviction that life
was beginning over again with the summer.”&lt;/p&gt;&lt;p&gt;-F. Scott Fitzgerald, The Great Gatsby&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I can ship something that is &lt;em&gt;good enough&lt;/em&gt; now and iterate on it quickly. If I
use what I&amp;#x27;m familiar with and make my content framework agnostic, I can produce
a working, non-naked website while leaving the future open for
&lt;a href=&quot;https://overreacted.io/optimized-for-change/&quot;&gt;change&lt;/a&gt;.
So, making like Sony with Spiderman, I rebooted my website
&lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/commit/e40a83626d199f0a91273572cbd52e93982362a5&quot;&gt;repo&lt;/a&gt;
using the
&lt;a href=&quot;https://www.gatsbyjs.org/starters/gatsbyjs/gatsby-starter-blog/&quot;&gt;Gatsby starter blog&lt;/a&gt;
template. All it took was:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;shell&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-shell line-numbers&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;gatsby new codyaprice.com https://github.com/gatsbyjs/gatsby-starter-blog&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Can’t repeat the past?…Why of course you can!&lt;/figcaption&gt;&lt;p&gt;and I was up and running 🏃‍♂️. Even though svelte is more
&lt;a href=&quot;https://svelte.dev/blog/write-less-code&quot;&gt;performant than React&lt;/a&gt;,
my development agility suffered when using it. Gatsby may take significantly
longer at build time than svelte, but I had my first Medium article self-hosted
and deployed faster than I could with native sapper. That&amp;#x27;s extremely valuable.
And so far, there&amp;#x27;s no reason to complain. Now I&amp;#x27;m freed up to focus on adding
features that matter, like
&lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/issues/1&quot;&gt;post tags and categories&lt;/a&gt;,
&lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/issues/2&quot;&gt;side/secondary navigation&lt;/a&gt;,
and other
&lt;a href=&quot;https://github.com/dev-cprice/codyaprice.com/issues/3&quot;&gt;routes&lt;/a&gt;.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;closing-remarks&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#closing-remarks&quot; aria-label=&quot;closing remarks permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Closing Remarks&lt;/h2&gt;&lt;p&gt;It&amp;#x27;s best to deliver as quick and as often as possible. A boss of mine has this
cartoon pinned on his office door and I think it&amp;#x27;s a perfect metaphor for this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/agile-like-this.png&quot; alt=&quot;Agile, like this&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Agile, but like this: 🛹➡️🚲️️➡️🏎&lt;/figcaption&gt;&lt;p&gt;In this scenario, you develop, ship, and demo to the client over and over
(iterate) until you arrive at what they want. The key is speed and you can&amp;#x27;t go
fast without the right support and tools. For me, that&amp;#x27;s React and Gatsby. For
now.&lt;/p&gt;&lt;p&gt;In one of Rich Harris&amp;#x27; tweet
&lt;a href=&quot;https://twitter.com/Rich_Harris/status/1120736046357131271?s=20&quot;&gt;threads&lt;/a&gt;
about his rethinking reactivity talk, he explains the ideas behind what makes
svelte so great. Dan Abramov
&lt;a href=&quot;https://twitter.com/dan_abramov/status/1120771116312690688?s=20&quot;&gt;replied&lt;/a&gt;
with some insights into what&amp;#x27;s to come with React + Suspense and the caveats/
nuances of his incredible and jaw-dropping
&lt;a href=&quot;https://www.youtube.com/watch?v=nLF0n9SACd4&quot;&gt;jsconf Iceland talk&lt;/a&gt;.
Sounds like React, like JavaScript, will be a safe
&lt;a href=&quot;http://brendaneich.github.io/ModernWeb.tw-2015/#74&quot;&gt;bet&lt;/a&gt;
for the near future.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0003-the-best-practice-is-shipping/images/horsejs-svelte-is-probably-better.png&quot; alt=&quot;Horse JS on Twitter: &amp;quot;Svelte is probably better, I don’t know but I’m pretty sure it is. But&amp;quot;&quot;/&gt;&lt;/p&gt;&lt;figcaption class=&quot;tweet&quot;&gt;Svelte is probably maybe better.. at some things.&lt;/figcaption&gt;&lt;p&gt;That being said, I believe that the direction svelte took is the future of web
development. In my spare time, I can revisit using svelte and sapper. Maybe
they&amp;#x27;ll have more support and features by then? Maybe then I&amp;#x27;ll have enough time
and experience to roll my own solutions that mimic what the Gatsby starter blog
gives you out of the box. 🤷‍♂️&lt;/p&gt;&lt;p&gt;I&amp;#x27;m still working on my personal website, but it&amp;#x27;s deployed live now and it has
(some) content on it. I can quickly add more without fighting a learning curve
and that&amp;#x27;s the most important thing right now. Who knows, maybe React and
Gatsby will satisfy my needs for years to come? One thing&amp;#x27;s for sure, knowing
the JavaScript scene, there will always be a new hot thing to try out. Today
it&amp;#x27;s svelte, tomorrow it&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;${hotNewJavaScriptFramework}&lt;/code&gt;. As long as I&amp;#x27;m
learning and growing along the way, that&amp;#x27;s all I can ask for!&lt;/p&gt;&lt;p&gt;Thanks for reading! ✌️&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Stop Testing Implementation Details]]></title><description><![CDATA[This was originally posted on  Medium on August 8, 2019 Yes, even you, object oriented peeps. 🐤😉 I’m so into the idea of testing code well…]]></description><link>https://codyaprice.com/blog/stop-testing-implementation-details/</link><guid isPermaLink="false">https://codyaprice.com/blog/stop-testing-implementation-details/</guid><pubDate>Thu, 08 Aug 2019 17:00:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;&lt;p&gt;This was originally posted on &lt;a href=&quot;https://medium.com/@dev.cprice/stop-testing-implementation-details-77a3528336af&quot;&gt;Medium on August 8, 2019&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Yes, even you, object oriented peeps. 🐤😉&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;I’m so into the idea of testing code well right now, especially when it comes to
best practices, methodologies, and philosophies. A lot of what I do on the daily
revolves around presentational (UI) code, specifically React. My org at work has
standardized around using &lt;a href=&quot;https://github.com/airbnb/enzyme&quot;&gt;enzyme&lt;/a&gt; and
&lt;a href=&quot;https://jestjs.io/&quot;&gt;jest&lt;/a&gt;. While I enjoy using jest, enzyme and I have a
complicated relationship (read as: I strongly dislike enzyme). So, I’ve been on
the lookout for better tools and methods to test our UI code so we can have
confidence that it does what we want. I’m currently writing up an initiative to
switch over to
&lt;a href=&quot;https://github.com/testing-library/react-testing-library&quot;&gt;react-testing-library&lt;/a&gt;
because it allows us to
&lt;a href=&quot;https://twitter.com/kentcdodds/status/977018512689455106&quot;&gt;write tests that resemble the way our software is used&lt;/a&gt;
and it makes it difficult to test implementation details, unlike enzyme which
often encourages it. &lt;strong&gt;In this article, this second point is what I want to
focus on.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0002-stop-testing-implementation-details/images/kcd-test-resemble-use.png&quot; alt=&quot;Kent C. Dodds on Twitter: &amp;quot;The more your tests resemble the way your software is used, the more confidence they can give you.&amp;quot;&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Kent C. Dodds on Twitter: &amp;quot;The more your tests resemble the way your software is used, the more confidence they can give you.&amp;quot;&lt;/figcaption&gt;&lt;h2 id=&quot;dont-write-tests-that-are-coupled-to-or-leak-out-your-implementation-details&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#dont-write-tests-that-are-coupled-to-or-leak-out-your-implementation-details&quot; aria-label=&quot;dont write tests that are coupled to or leak out your implementation details permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Don’t write tests that are coupled to or leak out your implementation details&lt;/h2&gt;&lt;p&gt;In my quest for improving my org’s tests and testing practice, I’ve come across
many great articles/blog posts on testing ideologies, like:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Eric Elliot: &lt;a href=&quot;https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a&quot;&gt;Mocking is a Code Smell&lt;/a&gt;
(preach! 🙏🗣)&lt;/li&gt;&lt;li&gt;Kent C. Dodds: &lt;a href=&quot;https://kentcdodds.com/blog/testing-implementation-details&quot;&gt;Testing Implementation Details&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A common theme in these posts is that your tests should be black box tests that
don’t leak implementation details, or things your consumers don’t care about or
are even aware of. As Kent C. Dodds put it, when you test implementation
details, it can lead to:&lt;/p&gt;&lt;blockquote&gt;&lt;ol&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;False negatives:&lt;/strong&gt; Can break when you refactor application code.&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;False positives:&lt;/strong&gt; May not fail when you break application code.&lt;/em&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/blockquote&gt;&lt;hr/&gt;&lt;h2 id=&quot;contrived-example-time-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#contrived-example-time-&quot; aria-label=&quot;contrived example time  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Contrived example time! ⏰&lt;/h2&gt;&lt;p&gt;Let’s say you’re a startup with limited resources (capital 💰) and you have an
idea for an awesome application which runs in an embedded environment. A key
feature of your application is that you can multiply two numbers. It’s
imperative that you get to market quickly so you can get paid.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0002-stop-testing-implementation-details/images/gotta-go-fast.gif&quot; alt=&quot;Gotta go fast!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Gotta go fast!&lt;/figcaption&gt;&lt;p&gt;Seeing as you are broke and you need to get to market first, you choose the
cheapest microprocessor available, but the catch is it doesn’t have a
multiplication hardware unit. However, it &lt;em&gt;&lt;strong&gt;does&lt;/strong&gt;&lt;/em&gt; have hardware accelerated
addition. Tradeoffs 🤷‍♂️. So, you get to work and write some code to multiply two
numbers using loops and addition:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; acc &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; sign &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sign&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Math&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    acc &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; acc&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Looping multiplication function between two numbers&lt;/figcaption&gt;&lt;p&gt;You’re a sane developer who follows TDD, so you write some tests for this as
well.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; multiply &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./multiply&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given any number and 0, it returns 0 regardless of order&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given any number and 1, it returns the other number regardless of order&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given any two positive numbers, it returns the positive expected result regardless of order&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given one positive and one negative number, it returns the negative expected result regardless of order&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given any two negative numbers, it returns the positive expected result regardless of order&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expected &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expected&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Testing multiplication module&lt;/figcaption&gt;&lt;p&gt;But wait ✋! Your boss comes back and is furious 😡 because you don’t have
&lt;a href=&quot;https://martinfowler.com/bliki/TestCoverage.html&quot;&gt;100% test coverage&lt;/a&gt;! So,
following orders 🤖, you add the following test:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; multiply &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./multiply&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// pretend we can &amp;quot;spy on&amp;quot; for loops, or worse, that&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// you refactor your code to call an add() method which&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// you spy on and then expect it to be called N times..&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;given 2 and 5, it should loop 5 times&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;spyOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// hol&amp;#x27; up: pretend we can spy on for loops 🕶&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; b &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; expectedCount &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toHaveBeenCalledTimes&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;expectedCount&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Testing multiplication module implementation details&lt;/figcaption&gt;&lt;p&gt;Hurray! We’ve hit 💯% coverage! Surely this isn’t foreshadowing! Now, you can
finally release to prod, get clients, and that first paycheck you’ve been
promised. 😎&lt;/p&gt;&lt;h2 id=&quot;enter-competitor-b&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#enter-competitor-b&quot; aria-label=&quot;enter competitor b permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Enter competitor B&lt;/h2&gt;&lt;p&gt;Competitor B promises the same features as your application, but with huge
performance benefits (especially when it comes to multiplication). Oh no 😰!
Well, at least your company can now afford to purchase a beefier microprocessor
that has hardware accelerated multiplication built in. So, you convince your
boss to buy new silicon, build up a prototype, and load your existing code on
it. Initially, itdoesn’t run any faster though. No worries, we just need to
change out the implementation of &lt;code class=&quot;language-text&quot;&gt;multiply&lt;/code&gt; so that it utilizes that hot new &lt;code class=&quot;language-text&quot;&gt;*&lt;/code&gt;
operator!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Simple (typical) multiply function between two numbers&lt;/figcaption&gt;&lt;p&gt;Easy. Clean. Solid. It runs beautifully on the new hardware. So fast!&lt;/p&gt;&lt;p&gt;Before opening a PR to bless your colleagues with the performance gains 💪, you
run your tests:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;✅✅✅✅✅❌&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;What?? &lt;em&gt;It’s just multiplication&lt;/em&gt;. The test that failed? The last one we wrote.
The one that tested and leaked implementation details. &lt;em&gt;&lt;strong&gt;This was a false
negative&lt;/strong&gt;&lt;/em&gt;. So long 100% test coverage.. 😩&lt;/p&gt;&lt;h2 id=&quot;what-value-did-the-test-that-leaked-implementation-details-give-us-none&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#what-value-did-the-test-that-leaked-implementation-details-give-us-none&quot; aria-label=&quot;what value did the test that leaked implementation details give us none permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What value did the test that leaked implementation details give us? None&lt;/h2&gt;&lt;p&gt;Actually, you can argue that it gave you &lt;em&gt;&lt;strong&gt;negative value&lt;/strong&gt;&lt;/em&gt;, or in other
words, it cost you. It cost you because it added noise to your tests and wasn’t
testing anything that actually mattered. It failed when the functionality
remained the same, but the hidden details under the covers changed. It failed
when we should’ve been celebrating the magnitudes of performance gains.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;cody-surely-this-is-just-a-hypothetical&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#cody-surely-this-is-just-a-hypothetical&quot; aria-label=&quot;cody surely this is just a hypothetical permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cody, surely this is just a hypothetical&lt;/h2&gt;&lt;p&gt;While the above example may be contrived, you can easily replace the application
and feature with any given idea or functionality in your own app’s core feature
set or internal business logic.&lt;/p&gt;&lt;p&gt;For example, let’s say that you’re wanting to keep a list of tags for an item in
your product catalogue. Do you implement this as an array of strings? A hashmap?
Linked list? Should we persist this in a database? Put it in the cloud? Install
one more dependency to manage it? Does it matter?&lt;/p&gt;&lt;p&gt;Well, according to my favorite engineering answer ever:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;It depends.&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2 id=&quot;lets-talk-about-trade-offs&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#lets-talk-about-trade-offs&quot; aria-label=&quot;lets talk about trade offs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Let&amp;#x27;s talk about trade-offs&lt;/h2&gt;&lt;p&gt;There’s always trade-offs for any given decision, implementation or otherwise.
Are you burdened with memory constraints? Does this code run in a hot path, so
anything &lt;code class=&quot;language-text&quot;&gt;O(n)&lt;/code&gt; or worse is a no go? Those are implementation concerns that
should definitely be addressed, but not within your tests. There’s another talk
about pre-optimization in here somewhere, but I digress.&lt;/p&gt;&lt;p&gt;When you test something, you should strive for testing its &lt;em&gt;&lt;strong&gt;functionality&lt;/strong&gt;&lt;/em&gt;,
or its public API. This does &lt;strong&gt;not&lt;/strong&gt; include internal state, if a certain method
was called N times or with certain arguments, etc.&lt;/p&gt;&lt;p&gt;As Kent C. Dodds states:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Implementation details are things which users of your code will not typically
use, see, or even know about.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The first five tests above are examples of testing the public API. They didn’t
fail when refactoring or changing the internal plumbing. Multiplication has a
public API, its
&lt;a href=&quot;https://www.khanacademy.org/math/pre-algebra/pre-algebra-arith-prop/pre-algebra-arithmetic-properties/a/properties-of-multiplication&quot;&gt;properties&lt;/a&gt;.
The above tests that target the properties of multiplication gave us confidence
that our code functions properly and weren’t fragile.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In closing, as developers, it is imperative that we strive for less fragile
tests that provide actual value to us. We need tests that prove functionality
and aren’t brittle. They shouldn’t reduce the signal-to-noise ratio.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How iOS VoiceOver Demonstrates The Power and Flexibility of React 💪]]></title><description><![CDATA[This was originally posted on  Medium on June 7, 2019 I was recently blessed with the opportunity to work on an extremely
high-priority…]]></description><link>https://codyaprice.com/blog/how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/</link><guid isPermaLink="false">https://codyaprice.com/blog/how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/</guid><pubDate>Fri, 07 Jun 2019 17:00:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;&lt;p&gt;This was originally posted on &lt;a href=&quot;https://medium.com/swlh/how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react-5369679b6a6b&quot;&gt;Medium on June 7, 2019&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I was recently blessed with the opportunity to work on an extremely
high-priority project which aimed to fix an accessibility bug in a multi-select
component. First I’ll discuss what we were dealing with and why it was an issue.
Then I’ll go into how we solved the underlying problem.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;: iOS VoiceOver is the new IE 🙅‍♂️ and React is awesome 😎&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s get started!&lt;/p&gt;&lt;p&gt;Let’s say there exists a legacy solution that is currently in production and is
in maintenance mode. This solution uses a tech stack that your company has moved
away from and you are not familiar with it at all. There’s a weird structure,
templates, and a bunch of code you don’t understand. All you know is is that
there’s an accessibility bug in a non-browser-native select/dropdown that is
rendered via some jQuery.&lt;/p&gt;&lt;p&gt;Okay, hypotheticals aside, this component is actually first rendered via a
Django template and then enhanced/decorated with an external dependency. The
component in question was actually using a
&lt;a href=&quot;https://select2.org/&quot;&gt;popular JavaScript dropreadown library: Select2&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0001-how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/images/select-2-multiselect-example.png&quot; alt=&quot;select2 MultiSelect Example&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Select2 MultiSelect Example&lt;/figcaption&gt;&lt;p&gt;The problem is that Select2 doesn’t provide a good user experience for iOS
VoiceOver users. Why is this? Well, it all comes down to two things: Apple’s
heuristics for the iOS VoiceOver virtual indicator are notoriously bad, and
there’s not an accessibility API to access when you’re a web app (thanks
Apple 😒). But, putting the blame on Apple (while justified 😤) doesn’t fix the
problem that the client has identified. As an engineer, we’re supposed to fix
problems, so let’s fix it! Before we can fix it, we must understand the problem.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;understanding-the-problem-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#understanding-the-problem-&quot; aria-label=&quot;understanding the problem  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Understanding the Problem 🤔&lt;/h2&gt;&lt;p&gt;So how does the virtual indicator work? For the most part, it follows the normal
DOM structure and tabIndex ordering. In general, where the focus is is where the
virtual indicator is (except when it’s not!). Where it breaks down is when
something in the DOM is only a sibling visually. This is generally achieved by
rendering content outside of the normal DOM flow (e.g. at the end of the body)
and applying CSS transforms to make the new content appear alongside the sibling
content.&lt;/p&gt;&lt;p&gt;How could you get into this kind of situation? &lt;strong&gt;Modals, popups, and
drop-downs&lt;/strong&gt;. For better or for worse (definitely for worse 🙃), our UX
department loves to build complex workflows with modals, popups, and drop-downs.
In all seriousness though, shoutout 🗣 to them for being a wonderful help in
guiding us through this problem 🙌.&lt;/p&gt;&lt;p&gt;Web-development is a type of engineering and with engineering comes trade-offs.
Select2 is not immune to this.&lt;/p&gt;&lt;p&gt;How does Select2 work? Well, here’s a simplified explanation. Let’s say you have
a multi-select workflow in a form and you have a list of data to select from
like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Red&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Orange&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Yellow&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Green&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Blue&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Indigo&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Violet&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Example list of colors&lt;/figcaption&gt;&lt;p&gt;Given this list, in a simplified world, when you render a Select2 multi-select
around a hidden input (used for your form submission), your screen will look
like:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0001-how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/images/select2-example-rendering-with-colors.png&quot; alt=&quot;select2 Example Rendering with List of Colors&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Example Select2 rendering given the data list of colors above&lt;/figcaption&gt;&lt;p&gt;And your corresponding DOM may look like the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-html line-numbers&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Select a color&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-container select2-container-multi&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-choices&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-search-choice&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- a selected choice here --&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Red&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-search-field&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- the Select2&amp;#x27;s input field --&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-input&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- the hidden input that is decorated with Select2 that will be used in the form submission --&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;hidden&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;red&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Submit Form&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-drop select2-drop-multi ...&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- this is the actual dropdown content, notice it&amp;#x27;s not a direct sibling of the Select2 itself --&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;ul&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-results&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Red&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Orange&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Yellow&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Green&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Blue&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Indigo&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;li&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;select2-result&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Violet&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;li&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;ul&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;DOM layout of a trivial Select2 Example&lt;/figcaption&gt;&lt;p&gt;Notice that the Select2 results aren’t a direct sibling of the Select2
container. This is the part that iOS VoiceOver trips up on.&lt;/p&gt;&lt;p&gt;Take another look at the screenshot of the Select2 dropdown above. How would you
expect the iOS VoiceOver virtual indicator to behave?&lt;/p&gt;&lt;p&gt;If you answered that the next navigation swipe lands on the dropdown options,
then you are sadly mistaken my friend 😢.
&lt;a href=&quot;https://www.destroyallsoftware.com/talks/wat&quot;&gt;WAT&lt;/a&gt;. WAT indeed..&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0001-how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/images/not-what-voiceover-navigates-to-next.png&quot; alt=&quot;This is NOT what iOS VoiceOver navigates to next when focused on the input&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;This is NOT what iOS VoiceOver navigates to next when focused on the input&lt;/figcaption&gt;&lt;p&gt;A keen eye will notice that there’s another focusable element between the
Select2 container div and the Select2 dropdown div: &lt;strong&gt;&lt;em&gt;the submit button&lt;/em&gt;&lt;/strong&gt;. In
more complicated forms, you’ll have many different fields between your dropdown
and the submit button which will just exacerbate the problem.&lt;/p&gt;&lt;p&gt;What iOS VoiceOver actually does is navigates through &lt;strong&gt;&lt;em&gt;the rest of the entire
DOM and THEN the dropdown options&lt;/em&gt;&lt;/strong&gt;. Yes, it’s THAT bad.&lt;/p&gt;&lt;hr/&gt;&lt;h2 id=&quot;fixing-whats-broken-with-react-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#fixing-whats-broken-with-react-&quot; aria-label=&quot;fixing whats broken with react  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fixing What’s Broken With React 🛠&lt;/h2&gt;&lt;p&gt;Now that we understand how we got here, how did we fix this with React (and the
native browser APIs)?&lt;/p&gt;&lt;p&gt;Remember how there was a hidden input in the example above? Well, we had one of
those generated from the Django template too. The specific hidden input we were
working with was given some handy
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes&quot;&gt;data attributes&lt;/a&gt;
which we were able to use to pass as props to a React tree. There were
attributes for things like a &lt;code class=&quot;language-text&quot;&gt;placeholder&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;maxSelection&lt;/code&gt; count, and a
&lt;code class=&quot;language-text&quot;&gt;searchUrl&lt;/code&gt; if the data was asynchronously fetched. There was also an attribute
we could use as a selector which would be one of two things: &lt;code class=&quot;language-text&quot;&gt;data-dynamic-list&lt;/code&gt;
or &lt;code class=&quot;language-text&quot;&gt;data-dropdown-list&lt;/code&gt;, the former being asynchronously loaded data and the
latter a typical static dropdown list.&lt;/p&gt;&lt;p&gt;One of the coolest things about React is that it’s so flexible. You can
incrementally
&lt;a href=&quot;https://reactjs.org/docs/add-react-to-a-website.html&quot;&gt;add it to a website&lt;/a&gt;.
What makes this so cool is that as long as there’s a container, you can
&lt;a href=&quot;https://reactjs.org/docs/rendering-elements.html#rendering-an-element-into-the-dom&quot;&gt;render React components inside it&lt;/a&gt;.
In our case, we have a container, which is the parent component of our hidden
inputs labeled with &lt;code class=&quot;language-text&quot;&gt;data-dynamic-list&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;data-dropdown-list&lt;/code&gt; attributes! All
we need is a little native browser API magic and we’ve got ‘em 🎯:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; dynamicList&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; dropdownList &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;codys-cool-react-stuff&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// wait for Django to load and render everything before we try to decorate with our custom React components :)&lt;/span&gt;
window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;load&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// get all the dynamic lists on the page&lt;/span&gt;
  document
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;[data-dynamic-list]&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;dynamicListElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// render a new React tree with this specific dynamic list&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;dynamicList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;dynamicListElement&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// get all the dropdown lists on the page&lt;/span&gt;
  document
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelectorAll&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;[data-dropdown-list]&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;dropdownListElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// render a new React tree with this specific dropdown list&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;dropdownList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;dropdownListElement&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Get all the dynamic and dropdown lists on the page&lt;/figcaption&gt;&lt;p&gt;Now that we have each of the lists on the page, we can replace them with a
container and render our custom React code inside them! Notice that this will
produce multiple React trees on the page if there are multiple dynamic and/or
dropdown lists 😉&lt;/p&gt;&lt;p&gt;Before we do that, we just need to extract the datasets from the list elements
and then we can pass those as props down to the React tree. This can be done as
simple as:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; dataset &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; element&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  isMultiple&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  placeholder&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  maxSelection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// etc,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; dataset&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Extracting the container&amp;#x27;s metadata from its dataset&lt;/figcaption&gt;&lt;p&gt;And now, since we want full control of the tree and therefore the hidden input
or select that is used for form submission, we can replace it with our
container:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;replaceNodeWithContainer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; parentElement &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; container &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;div&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  parentElement&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;replaceChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; container&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Replace the given node with a React tree container&lt;/figcaption&gt;&lt;p&gt;Now all that’s left to do is put it all together and render our custom
component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; render &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-dom&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; getContainer &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./utils/getContainer&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; SearchableSelection &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./components/SearchableSelection&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;dynamicList&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; id &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; node&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; dataset &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataset &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    placeholderText&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    maximumSelection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    searchUrl&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    additionalQueryParams&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    isMultiple&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; dataset&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; placeholder &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; placeholderText &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; maxSelection &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; isMultiple
    &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;parseInt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;maximumSelection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;undefined&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; container &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getContainer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;node&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; props &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    selectId&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    searchUrl&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    placeholder&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    isMultiple&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    maxSelection&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    additionalQueryParams&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    searchThreshold&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; component &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;SearchableSelection &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;component&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; container&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Render Our Custom React Select2 Dynamic List Replacement&lt;/figcaption&gt;&lt;p&gt;With this full control, we can use the magic of
&lt;a href=&quot;https://reactjs.org/docs/refs-and-the-dom.html&quot;&gt;refs&lt;/a&gt; to manipulate the hidden
&lt;code class=&quot;language-text&quot;&gt;input&lt;/code&gt; and/or &lt;code class=&quot;language-text&quot;&gt;select&lt;/code&gt; nodes.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0001-how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/images/noice.gif&quot; alt=&quot;noice!&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Noice!&lt;/figcaption&gt;&lt;hr/&gt;&lt;h2 id=&quot;the-result-drumroll-please-🥁&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#the-result-drumroll-please-%F0%9F%A5%81&quot; aria-label=&quot;the result drumroll please 🥁 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Result: Drumroll Please.. 🥁&lt;/h2&gt;&lt;p&gt;So, with all that work, what do we have to show for it? Well, I can’t show the
rest of the code (company secret 🤫😉). However, we now have a responsive and
accessible multi-select asynchronous dropdown!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://d1jubymwibgxp.cloudfront.net/blog/0001-how-ios-voiceover-demonstrates-the-power-and-flexibility-of-react/images/responsive-a11y-dropdown-select.png&quot; alt=&quot;Responsive and Accessible Asynchronous MultiSelect Dropdown&quot;/&gt;&lt;/p&gt;&lt;figcaption&gt;Responsive and Accessible Asynchronous MultiSelect Dropdown&lt;/figcaption&gt;&lt;p&gt;We ended up responsively rendering a modal where the dropdown options are a
direct sibling of the search input. There are a few interesting gotchas that we
ran into, however.&lt;/p&gt;&lt;p&gt;Normally on the web, window size is sufficient for mobile device detection.
However, our clients frequently operate on iPads, which can be much larger than
the typical mobile screen size and appear as if it was a desktop device if we
only paid attention to the window width. So, we detect if we were at a mobile
breakpoint or if &lt;code class=&quot;language-text&quot;&gt;&amp;#x27;ontouchstart&amp;#x27; in window&lt;/code&gt; (better than User Agent string
parsing 🙌).&lt;/p&gt;&lt;p&gt;When we open the modal, the virtual indicator wasn’t initially moving to it.To
fix this, we used a ref to focus on the close button in the top right. We
initially tried to focus on the h1 title, but iOS VoiceOver really only likes it
when you programmatically change focus onto &lt;strong&gt;&lt;em&gt;interactable elements&lt;/em&gt;&lt;/strong&gt;.
🎶&lt;em&gt;Easy like Sunday mornin’&lt;/em&gt; 🎶&lt;/p&gt;&lt;p&gt;The presence of both the &lt;code class=&quot;language-text&quot;&gt;X&lt;/code&gt; (close) and &lt;code class=&quot;language-text&quot;&gt;Apply&lt;/code&gt; buttons was an interesting
choice by UX. This implies that clicking on the &lt;code class=&quot;language-text&quot;&gt;X&lt;/code&gt; will cancel your changes,
while clicking on &lt;code class=&quot;language-text&quot;&gt;Apply&lt;/code&gt; will commit them. So, while the state of what was
selected in each dropdown was
&lt;a href=&quot;https://reactjs.org/docs/lifting-state-up.html&quot;&gt;lifted up&lt;/a&gt;,
we needed to maintain a &lt;em&gt;local state&lt;/em&gt; within the modal component when it was
open. Only when we clicked submit would we commit (apply) our changes. So, we
initialized the local selections state with the &lt;em&gt;current state of the parent&lt;/em&gt;
and then maintained local selection state as normal
(&lt;a href=&quot;https://reactjs.org/docs/hooks-intro.html&quot;&gt;shameless plug for hooks 🎣&lt;/a&gt;).
We would pass the local selection state back to the parent through an &lt;code class=&quot;language-text&quot;&gt;onApply&lt;/code&gt;
callback when the user clicked the &lt;code class=&quot;language-text&quot;&gt;Apply&lt;/code&gt; button. Pretty neat 📸&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre style=&quot;counter-reset:linenumber NaN&quot; class=&quot;language-js line-numbers&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; PropTypes &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;prop-types&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; propTypes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ..., other props&lt;/span&gt;
  onApply&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;func&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  selections&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;arrayOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;string&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isRequired&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      text&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;string&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isRequired&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; defaultProps &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ...,&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;onApply&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  selections&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Modal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; selections&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;otherProps &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// initialize localSelections state with selections prop given :)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;localSelections&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setLocalSelections&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;selections&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;handleOnApply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// pass the localSelections onto the parent component through&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// the onApply callback prop :D&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;onApply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;localSelections&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* hidden stuff ;) */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;button&amp;quot;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleOnApply&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        Apply
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

Modal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;propTypes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; propTypes&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
Modal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;defaultProps &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; defaultProps&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; Modal&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;line-numbers-rows&quot; style=&quot;white-space:normal;width:auto;left:0&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figcaption&gt;Handling Local Modal State&lt;/figcaption&gt;&lt;hr/&gt;&lt;h2 id=&quot;in-conclusion-&quot; style=&quot;position:relative&quot;&gt;&lt;a href=&quot;#in-conclusion-&quot; aria-label=&quot;in conclusion  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;In Conclusion 🎬&lt;/h2&gt;&lt;p&gt;This project was definitely one of my favorites to work on so far. It has been
challenging and really rewarding. As engineers, it can sometimes seem that a
limitation in an OS or API prevents us from proceeding forward. Often times
though, this is simply an opportunity to flex our thinkin’ muscles and provide a
novel solution to a complex problem. In tackling this, I’ve definitely learned a
lot about the power of the browser APIs and React, as well as how hard it can be
to get accessibility right. I also want to thank the engineers that have helped
me along the way, as well as our UX department for providing us with visuals and
a different workflow on such short notice 🚀.&lt;/p&gt;&lt;p&gt;I was already a huge fan of React ⚛︎ before this, but it definitely solidifies my
appreciation for the framework. I hope you have learned something and have
enjoyed the read. Let me know what you thought in the comments below! ✌️&lt;/p&gt;</content:encoded></item></channel></rss>