<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BlackJosh007</title>
    <description>The latest articles on DEV Community by BlackJosh007 (@blackjosh007).</description>
    <link>https://dev.to/blackjosh007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3427851%2Fac26d1b8-8dfb-4674-b681-30075d5eb552.png</url>
      <title>DEV Community: BlackJosh007</title>
      <link>https://dev.to/blackjosh007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/blackjosh007"/>
    <language>en</language>
    <item>
      <title>My Timer Kept Doubling — and It Took Me a Real Bug to Actually Understand useEffect</title>
      <dc:creator>BlackJosh007</dc:creator>
      <pubDate>Fri, 04 Sep 2026 00:28:21 +0000</pubDate>
      <link>https://dev.to/blackjosh007/my-timer-kept-doubling-and-it-took-me-a-real-bug-to-actually-understand-useeffect-21o9</link>
      <guid>https://dev.to/blackjosh007/my-timer-kept-doubling-and-it-took-me-a-real-bug-to-actually-understand-useeffect-21o9</guid>
      <description>&lt;p&gt;I finished my Tenzies capstone project (built with React) and I want to talk about the one bug that taught me more than any tutorial did.&lt;/p&gt;

&lt;p&gt;🔗 Live demo: tenzies-six-silk.vercel.app&lt;br&gt;
🔗 Code: github.com/BlackJosh007/tenzies&lt;/p&gt;

&lt;p&gt;I was adding a timer — track how long it takes a player to win. Simple feature, I thought. I set up &lt;code&gt;useState&lt;/code&gt; for the elapsed time, &lt;code&gt;useRef&lt;/code&gt; for the interval ID, and a &lt;code&gt;useEffect&lt;/code&gt; to start the interval once the player held their first die.&lt;/p&gt;

&lt;p&gt;It worked... sometimes. Other times my timer would double up out of nowhere, ticking twice as fast. And at one point, after a few touches, it stopped running entirely.&lt;/p&gt;

&lt;p&gt;Here's why.&lt;/p&gt;

&lt;h3&gt;
  
  
  The wrong belief I was carrying
&lt;/h3&gt;

&lt;p&gt;I thought the cleanup function in &lt;code&gt;useEffect&lt;/code&gt; only ran once — when the component unmounted. That's what I'd taken away from the tutorial. Knowledge, filed away, never tested.&lt;/p&gt;

&lt;p&gt;What actually happens: the cleanup function runs before &lt;em&gt;every&lt;/em&gt; re-run of the effect, not just on unmount. Every time your dependency changes, React cleans up the previous effect first, then runs the new one.&lt;/p&gt;

&lt;p&gt;I didn't have that cleanup wired in properly. So every time my dependency array changed, a new &lt;code&gt;setInterval&lt;/code&gt; was created — without the old one being cleared. Two intervals running at once. Then three. My timer wasn't buggy, it was doing exactly what I told it to do.&lt;/p&gt;

&lt;h3&gt;
  
  
  It got worse before it got better
&lt;/h3&gt;

&lt;p&gt;My first instinct for triggering the timer was checking &lt;code&gt;diceNo.includes({ isHeld: true })&lt;/code&gt; inside the effect, with &lt;code&gt;seconds&lt;/code&gt; as my dependency array. That's a double mistake: &lt;code&gt;.includes&lt;/code&gt; doesn't do the deep comparison I wanted (switched to &lt;code&gt;.some(die =&amp;gt; die.isHeld)&lt;/code&gt; later), and using &lt;code&gt;seconds&lt;/code&gt; as the dependency meant the effect was re-running every single tick — re-arming a new interval on top of the old one, every second.&lt;/p&gt;

&lt;p&gt;I also had a second wrong belief here: I assumed that if I wrapped my interval logic in an &lt;code&gt;if&lt;/code&gt; statement inside the effect, only the code &lt;em&gt;inside&lt;/em&gt; the &lt;code&gt;if&lt;/code&gt; block counted as "the effect." Not true — the entire function body passed to &lt;code&gt;useEffect&lt;/code&gt; is the effect, condition or no condition. React doesn't care what's inside your &lt;code&gt;if&lt;/code&gt;; it re-runs the whole thing whenever the dependency changes.&lt;/p&gt;

&lt;p&gt;Once I fixed the dependency array (moved to &lt;code&gt;diceNo&lt;/code&gt;, gated by a &lt;code&gt;timerStarted&lt;/code&gt; ref so the interval only ever arms once) and got the cleanup returning &lt;code&gt;clearInterval(intervalRef.current)&lt;/code&gt; properly, the doubling stopped.&lt;/p&gt;

&lt;h3&gt;
  
  
  The bonus realization
&lt;/h3&gt;

&lt;p&gt;While staring at &lt;code&gt;setInterval(() =&amp;gt; setMilliSeconds(prev =&amp;gt; prev + 10), 10)&lt;/code&gt;, I genuinely wondered if React was re-rendering every 10ms because of it. Turns out — no. &lt;code&gt;setInterval&lt;/code&gt; is handed off to the browser, not React. React only re-renders when the state update inside the callback actually fires, and it's the state update — not the timer itself — that's on React's clock.&lt;/p&gt;

&lt;h3&gt;
  
  
  Knowledge vs. understanding
&lt;/h3&gt;

&lt;p&gt;I'd "learned" useEffect and its dependency array from a tutorial before this. I could've told you the definition. But I didn't &lt;em&gt;understand&lt;/em&gt; it until a real bug forced me to. That's the difference — knowledge is something you can repeat, understanding is something you can debug.&lt;/p&gt;

&lt;h3&gt;
  
  
  One thing I changed my mind on
&lt;/h3&gt;

&lt;p&gt;Last post, I said I wanted to add full keyboard navigation to this game. I'm not doing that anymore. Tenzies is an abstract, casual game — realistically, almost everyone playing it will be on a phone, not a desktop with a keyboard. Building out keyboard nav for a demographic that mostly won't use it didn't make sense once I actually thought about who's playing. Instead, I put that time into a timer, roll counter, restart button, and a highscore overlay — features that matter regardless of device.&lt;/p&gt;

&lt;p&gt;Onto the next build.&lt;/p&gt;

</description>
      <category>buildinpublic</category>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title># I Shipped a Working Win-Check... That Could Be Wrong 9 Times Out of 10</title>
      <dc:creator>BlackJosh007</dc:creator>
      <pubDate>Sat, 29 Aug 2026 20:40:51 +0000</pubDate>
      <link>https://dev.to/blackjosh007/-i-shipped-a-working-win-check-that-could-be-wrong-9-times-out-of-10-48b0</link>
      <guid>https://dev.to/blackjosh007/-i-shipped-a-working-win-check-that-could-be-wrong-9-times-out-of-10-48b0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs3juzenj94p4lmzv7g3w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs3juzenj94p4lmzv7g3w.png" alt=" " width="800" height="769"&gt;&lt;/a&gt;While building &lt;strong&gt;Tenzies&lt;/strong&gt; (my React capstone from freeCodeCamp), I hit a problem that looked simple on the surface: check if the player won.&lt;/p&gt;

&lt;p&gt;The rule is easy to say out loud: &lt;em&gt;all 10 dice must be held, and all 10 must show the same value.&lt;/em&gt; Turning that into code taught me more about array logic than any tutorial had so far — mostly because my first version had a bug I didn't even know to look for.&lt;/p&gt;

&lt;h2&gt;
  
  
  My First Attempt
&lt;/h2&gt;

&lt;p&gt;I reached for a &lt;code&gt;for&lt;/code&gt; loop and a counter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;isHeld&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;you won&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The logic, in my head: compare each die to the &lt;em&gt;next&lt;/em&gt; die. If they match in value and the current one is held, count it. With 10 dice, there are 9 pairs — so if all 9 comparisons pass, count hits 9, and that means everyone matches. Right?&lt;/p&gt;

&lt;p&gt;It worked. I tested it, saw "you won" print at the right time, and felt genuinely proud — until I looked at the instructor's solution and saw the whole thing done in three lines with &lt;code&gt;.every()&lt;/code&gt;. My first reaction was honestly "that feels like cheating." My second, more useful reaction was: &lt;em&gt;wait, is my version even correct?&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bug I Almost Missed
&lt;/h2&gt;

&lt;p&gt;Look closely at the loop bounds: &lt;code&gt;i &amp;lt; diceNo.length - 1&lt;/code&gt;. With 10 dice, &lt;code&gt;i&lt;/code&gt; runs from 0 to 8. The &lt;code&gt;isHeld&lt;/code&gt; check only ever runs on &lt;code&gt;diceNo[i]&lt;/code&gt; — &lt;strong&gt;the last die, at index 9, never gets its &lt;code&gt;isHeld&lt;/code&gt; checked at all.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So picture this scenario: dice 0 through 8 are all held and all show a 4. Die 9 shows a 4 too, purely by chance, but the player never held it. My loop would still count 9 matches and declare a win — even though one die was never actually locked in by the player. The bug isn't loud; it only shows up in a specific edge case, which is exactly why I didn't catch it just by playing the game normally.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gameWon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;die&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;die&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isHeld&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;die&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;die&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;diceNo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;gameWon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two separate, symmetric checks: &lt;em&gt;are all 10 held?&lt;/em&gt; and &lt;em&gt;do all 10 match the first die's value?&lt;/em&gt; Every die gets checked, every time, with no off-by-one gap hiding at the edges. That's the real reason this version is better — not brevity for its own sake, but that it's structurally impossible to skip a die.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Lesson
&lt;/h2&gt;

&lt;p&gt;The takeaway for me isn't "loops bad, array methods good." It's this: &lt;strong&gt;when a loop's bounds don't map 1:1 to "check every item," ask what you're actually excluding — and whether that exclusion is intentional.&lt;/strong&gt; &lt;code&gt;.every()&lt;/code&gt; forced correctness by construction. My loop left a gap I had to go looking for.&lt;/p&gt;

&lt;p&gt;Also — I've officially learned to check whether a built-in method already solves my problem &lt;em&gt;before&lt;/em&gt; I hand-roll a loop and a counter. Lesson paid for in stress, but paid.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;I'm planning to extend the game with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A timer + roll counter, to track how fast you can win&lt;/li&gt;
&lt;li&gt;Dice styled with actual pips instead of numbers&lt;/li&gt;
&lt;li&gt;Full keyboard navigation for accessibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; &lt;a href="https://tenzies-six-silk.vercel.app/" rel="noopener noreferrer"&gt;https://tenzies-six-silk.vercel.app/&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Repo:&lt;/strong&gt; &lt;a href="https://github.com/BlackJosh007/tenzies" rel="noopener noreferrer"&gt;https://github.com/BlackJosh007/tenzies&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Wait, Square Brackets Aren't Just for Arrays? — A Controlled Component Gotcha</title>
      <dc:creator>BlackJosh007</dc:creator>
      <pubDate>Fri, 21 Aug 2026 15:21:08 +0000</pubDate>
      <link>https://dev.to/blackjosh007/wait-square-brackets-arent-just-for-arrays-a-controlled-component-gotcha-539m</link>
      <guid>https://dev.to/blackjosh007/wait-square-brackets-arent-just-for-arrays-a-controlled-component-gotcha-539m</guid>
      <description>&lt;p&gt;While building a meme generator with React (following freeCodeCamp), I hit a moment where my mental model of JavaScript syntax completely betrayed me — and untangling it taught me something I won't forget.&lt;/p&gt;

&lt;p&gt;I was building a controlled component: two text inputs (top text, bottom text) that update state as the user types. Here's the handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTarget&lt;/span&gt;

    &lt;span class="nf"&gt;setMemeText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevMeme&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;prevMeme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;[name]: value&lt;/code&gt; line stopped me cold. In my head, square brackets meant one thing: arrays. So my brain tried to read this as some kind of array operation happening &lt;em&gt;inside&lt;/em&gt; an object spread, and none of it made sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was actually going on
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;[name]&lt;/code&gt; is a &lt;strong&gt;computed property name&lt;/strong&gt;. &lt;code&gt;name&lt;/code&gt; is a variable holding a string — in this case, either &lt;code&gt;"topText"&lt;/code&gt; or &lt;code&gt;"bottomText"&lt;/code&gt; (pulled from the input's &lt;code&gt;name&lt;/code&gt; attribute). Wrapping it in square brackets tells JavaScript: "don't use the literal word &lt;code&gt;name&lt;/code&gt; as the key — evaluate this variable and use &lt;em&gt;its value&lt;/em&gt; as the key instead."&lt;/p&gt;

&lt;p&gt;Without the brackets, &lt;code&gt;{ ...prevMeme, name: value }&lt;/code&gt; would spread the previous state and then literally add a property called &lt;code&gt;name&lt;/code&gt; set to whatever was typed. That's not what I wanted — I wanted the actual key to be &lt;code&gt;topText&lt;/code&gt; or &lt;code&gt;bottomText&lt;/code&gt;, depending on which input fired the event. The brackets are the difference between "the key is the word &lt;code&gt;name&lt;/code&gt;" and "the key is &lt;em&gt;whatever &lt;code&gt;name&lt;/code&gt; currently equals&lt;/em&gt;."&lt;/p&gt;

&lt;p&gt;One line, one small syntax convention, and suddenly one function could handle both inputs instead of writing a separate handler for each.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full context — the input side
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"topText"&lt;/span&gt;
    &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;memeText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;topText&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;name="topText"&lt;/code&gt; on the JSX element is what flows into &lt;code&gt;event.currentTarget.name&lt;/code&gt; — which is then the value that &lt;code&gt;[name]&lt;/code&gt; computes from. Once I traced that full loop — JSX attribute → event object → destructured variable → computed key — it clicked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;If square brackets in an object literal ever throw you off, ask whether you're looking at a computed property name rather than an array. It's a small piece of syntax that does a lot of quiet work.&lt;/p&gt;

&lt;p&gt;Still working through the freeCodeCamp React course — challenge sections left before I move on to real project builds.&lt;/p&gt;

&lt;p&gt;🔗 Code: [&lt;a href="https://github.com/BlackJosh007/chef-claude-app" rel="noopener noreferrer"&gt;https://github.com/BlackJosh007/chef-claude-app&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The React Concept That Broke My Brain (And Why It Was Actually Simple)</title>
      <dc:creator>BlackJosh007</dc:creator>
      <pubDate>Tue, 28 Jul 2026 23:53:11 +0000</pubDate>
      <link>https://dev.to/blackjosh007/the-react-concept-that-broke-my-brain-and-why-it-was-actually-simple-22km</link>
      <guid>https://dev.to/blackjosh007/the-react-concept-that-broke-my-brain-and-why-it-was-actually-simple-22km</guid>
      <description>&lt;p&gt;I almost skipped past this. It looked like a small refactor. It ended up being the first time React's "one source of truth" idea actually clicked for me instead of just being a phrase I nodded along to.&lt;/p&gt;

&lt;p&gt;Here's the project: a grid of colored pads that toggle on/off when clicked. Simple UI, simple idea.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I started: derived state
&lt;/h2&gt;

&lt;p&gt;My first instinct was to create state based on data that lived somewhere else in the component tree — what's usually called &lt;em&gt;derived state&lt;/em&gt;. It technically worked. Buttons rendered, colors showed up. But something about it felt fragile, and I couldn't articulate why yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I ended up: one source of truth
&lt;/h2&gt;

&lt;p&gt;The fix was to move the actual state up into &lt;code&gt;App.jsx&lt;/code&gt;, and have everything else just receive data and functions as props. My folder looks like this:&lt;br&gt;
&lt;strong&gt;1. &lt;code&gt;App.jsx&lt;/code&gt;&lt;/strong&gt; — holds the single source of truth:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;pads&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPads&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;padsData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;idR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setPads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevPads&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prevPads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;idR&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;buttonElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pad&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Pad&lt;/span&gt;
      &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;toggleFunc&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggle&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"pad-container"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;buttonElements&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;pads.js&lt;/code&gt;&lt;/strong&gt; — the raw data the state is initialized from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#F18D8B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#F5C280&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;Pad.jsx&lt;/code&gt;&lt;/strong&gt; — a dumb component that just renders and reports back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Pad&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
      &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;on&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;toggleFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The part that actually confused me
&lt;/h3&gt;

&lt;p&gt;Not the state move itself — that part I could follow. What genuinely took time to reconcile was &lt;strong&gt;passing a function as a prop and tracking two different names for the same value&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;Pad.jsx&lt;/code&gt;: &lt;code&gt;onClick={() =&amp;gt; toggleFunc(id)}&lt;/code&gt; — here, &lt;code&gt;id&lt;/code&gt; is the &lt;em&gt;real&lt;/em&gt; value, the actual id of the button that got clicked.&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;App.jsx&lt;/code&gt;: &lt;code&gt;function toggle(idR)&lt;/code&gt; — here, &lt;code&gt;idR&lt;/code&gt; is just a &lt;em&gt;placeholder name&lt;/em&gt;, a parameter waiting to receive whatever value gets passed in.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I kept reading &lt;code&gt;idR&lt;/code&gt; like it meant something special, like it was doing extra work. It isn't. It's just a name. The moment I stopped trying to find hidden meaning in &lt;code&gt;idR&lt;/code&gt; and just traced the value — click happens → &lt;code&gt;id&lt;/code&gt; gets passed → &lt;code&gt;toggle&lt;/code&gt; receives it as &lt;code&gt;idR&lt;/code&gt; → &lt;code&gt;idR&lt;/code&gt; gets compared against each item in state — the whole thing clicked into place.&lt;/p&gt;

&lt;h3&gt;
  
  
  The full loop, in plain language
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;App.jsx&lt;/code&gt; holds &lt;code&gt;pads&lt;/code&gt; state, seeded from &lt;code&gt;padsData&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It maps over &lt;code&gt;pads&lt;/code&gt; and renders a &lt;code&gt;Pad&lt;/code&gt; for each one, passing down &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;on&lt;/code&gt;, &lt;code&gt;id&lt;/code&gt;, and the &lt;code&gt;toggle&lt;/code&gt; function itself.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Pad.jsx&lt;/code&gt; attaches &lt;code&gt;toggle&lt;/code&gt; to its button's &lt;code&gt;onClick&lt;/code&gt;, wrapped in an arrow function so it can pass along &lt;em&gt;which&lt;/em&gt; button was clicked.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toggle&lt;/code&gt; receives that id (as &lt;code&gt;idR&lt;/code&gt;), and calls &lt;code&gt;setPads&lt;/code&gt;, mapping over the previous state and flipping &lt;code&gt;on&lt;/code&gt; only for the item whose id matches.&lt;/li&gt;
&lt;li&gt;React re-renders with the updated state, and only the clicked button's color state changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why this matters more than it looks like
&lt;/h3&gt;

&lt;p&gt;The bug I would've eventually hit with derived state is the classic one: two sources of truth drifting out of sync. Lifting the state up removes that possibility entirely — there's exactly one place the "real" data lives, and everything else is just a reflection of it.&lt;/p&gt;

&lt;p&gt;This is day-something of learning React in public, building toward real projects instead of just finishing tutorials. If you've hit this same wall with props/state, I'd like to hear how you reasoned through it.&lt;/p&gt;

&lt;p&gt;Repo's on GitHub if you want to see the full thing — link in my profile.&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
