<?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: Ragaeeb</title>
    <description>The latest articles on DEV Community by Ragaeeb (@synonymous2).</description>
    <link>https://dev.to/synonymous2</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F255693%2F5f915ceb-1bf1-4863-ac6a-8e457a41fbcd.jpeg</url>
      <title>DEV Community: Ragaeeb</title>
      <link>https://dev.to/synonymous2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/synonymous2"/>
    <language>en</language>
    <item>
      <title>🚀 useMutableState: Tiny state management hook to easily edit deeply nested properties</title>
      <dc:creator>Ragaeeb</dc:creator>
      <pubDate>Tue, 18 Feb 2025 21:59:54 +0000</pubDate>
      <link>https://dev.to/synonymous2/usemutablestate-tiny-state-management-hook-to-easily-edit-deeply-nested-properties-3kn</link>
      <guid>https://dev.to/synonymous2/usemutablestate-tiny-state-management-hook-to-easily-edit-deeply-nested-properties-3kn</guid>
      <description>&lt;p&gt;After years of frustration with React’s immutability rules—constantly spreading state just to update a nested property—I decided enough was enough. The code was cluttered, error-prone, and hard to read.&lt;/p&gt;

&lt;p&gt;So, I built useMutableState(), a tiny React hook that leverages the Proxy pattern to make deep state updates effortless. No more spreading—just mutate directly, and React handles the rest!&lt;/p&gt;

&lt;p&gt;Turn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, setState] = useState({
    level1: { level2: { level3: { level4: { count: 0 } } } },
});

const increment = () =&amp;gt; {
    setState((prev) =&amp;gt; ({
        ...prev,
        level1: {
            ...prev.level1,
            level2: {
                ...prev.level1.level2,
                level3: {
                    ...prev.level1.level2.level3,
                    level4: {
                        ...prev.level1.level2.level3.level4,
                        count: prev.level1.level2.level3.level4.count + 1,
                    },
                },
            },
        },
    }));
};

return (
    &amp;lt;div&amp;gt;
        &amp;lt;h3&amp;gt;Count: {state.level1.level2.level3.level4.count}&amp;lt;/h3&amp;gt;
        &amp;lt;button onClick={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const state = useMutableState({
        level1: { level2: { level3: { level4: { count: 0 } } } },
    });

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;h3&amp;gt;Count: {state.level1.level2.level3.level4.count}&amp;lt;/h3&amp;gt;
            &amp;lt;button onClick={() =&amp;gt; state.level1.level2.level3.level4.count++}&amp;gt;Increment&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    );

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔗 See it in action: &lt;a href="https://ragaeeb.github.io/use-mutable-state-hook" rel="noopener noreferrer"&gt;Demo&lt;/a&gt;&lt;br&gt;
💻 Check out the code: &lt;a href="https://github.com/ragaeeb/use-mutable-state-hook" rel="noopener noreferrer"&gt;Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bug reports are welcome! 🚀&lt;/p&gt;

&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.amazonaws.com%2Fuploads%2Farticles%2Fuf7kinqf1mrvucd555kn.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.amazonaws.com%2Fuploads%2Farticles%2Fuf7kinqf1mrvucd555kn.png" alt="Image description" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&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.amazonaws.com%2Fuploads%2Farticles%2Fnull39fsclk3db6mstn2.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.amazonaws.com%2Fuploads%2Farticles%2Fnull39fsclk3db6mstn2.png" alt="Image description" width="800" height="801"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>opensource</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
