<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ramer Matic on Medium]]></title>
        <description><![CDATA[Stories by Ramer Matic on Medium]]></description>
        <link>https://medium.com/@rjmatic19?source=rss-40afeb7c9b8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-w0LEbi70wmolill</url>
            <title>Stories by Ramer Matic on Medium</title>
            <link>https://medium.com/@rjmatic19?source=rss-40afeb7c9b8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:00:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rjmatic19/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Goodbye useState Boilerplate: Exploring React 19’s useActionState]]></title>
            <link>https://medium.com/@rjmatic19/goodbye-usestate-boilerplate-exploring-react-19s-useactionstate-68bfaf3432fa?source=rss-40afeb7c9b8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/68bfaf3432fa</guid>
            <category><![CDATA[react-19-new-features]]></category>
            <category><![CDATA[react-19-use-explained]]></category>
            <category><![CDATA[react-19-features]]></category>
            <category><![CDATA[react-19-updates]]></category>
            <category><![CDATA[react-19]]></category>
            <dc:creator><![CDATA[Ramer Matic]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 11:05:37 GMT</pubDate>
            <atom:updated>2025-06-07T11:15:02.765Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever found yourself tangled in a web of useState, useEffect, and isSubmitting flags just to handle a simple form — React 19 has some exciting news. The new useActionState hook introduces a cleaner, declarative way to manage state updates, especially for asynchronous actions like form submissions.</p><p>In this article, I’ll explore how useActionState is reshaping the way we think about state in modern React apps — and why it’s especially powerful when combined with <strong>Next.js 15’s App Router</strong> and <strong>Server Actions</strong>.</p><h3>🧠 What is useActionState?</h3><p>useActionState is a React hook designed to handle:</p><ul><li>✅ The <strong>current state</strong> value</li><li>✅ An <strong>async or sync function</strong> that performs a state mutation</li><li>✅ A built-in isPending flag to reflect transitions/loading states</li><li>✅ Optional support for <strong>payloads</strong> (e.g. form data)</li></ul><p>It effectively replaces the need for juggling multiple useState hooks and manually tracking loading/error states in most interactive UI cases.</p><h3>🧬 Understanding useActionState&#39;s Flexibility</h3><p>React’s useActionState hook comes in two variations — one with a payload, and one without — giving you the flexibility to manage both simple and complex state updates.</p><h4>📌 Variant 1: Without Payload</h4><pre>useActionState&lt;State&gt;(<br>  action: (state: Awaited&lt;State&gt;) =&gt; State | Promise&lt;State&gt;,<br>  initialState: Awaited&lt;State&gt;,<br>  permalink?: string<br>): [state: Awaited&lt;State&gt;, dispatch: () =&gt; void, isPending: boolean]</pre><p>Use this when your action doesn’t rely on any external input beyond the current state — ideal for toggles, counters, or local-only updates.</p><h4>📌Variant 2: With Payload</h4><pre>useActionState&lt;State, Payload&gt;(<br>  action: (state: Awaited&lt;State&gt;, payload: Payload) =&gt; State | Promise&lt;State&gt;,<br>  initialState: Awaited&lt;State&gt;,<br>  permalink?: string<br>): [state: Awaited&lt;State&gt;, dispatch: (payload: Payload) =&gt; void, isPending: boolean]</pre><p>Use this when you need to update state based on <strong>form data</strong>, <strong>user input</strong>, or <strong>external events</strong> — the most common use case in interactive UIs.</p><h3>🧩 Parameter Breakdown</h3><ul><li><strong>action</strong>: A function that receives the current state and (optionally) a payload. It returns the updated state, either synchronously or as a Promise.</li><li><strong>initialState</strong>: Just like useState, this sets the default value of your state.</li><li><strong>permalink</strong> (optional): Used internally by React for tracking and debugging action calls — useful for devtools or server tracing.</li><li><strong>Return value</strong>:</li></ul><pre>[state, dispatch, isPending]</pre><ul><li>state: The current state value</li><li>dispatch: A function to trigger your action (optionally with a payload)</li><li>isPending: A boolean that tells you if an action is currently running (great for showing loading states)</li></ul><h3>A Simple Example of useActionState in Action</h3><p>To make this more concrete, here’s a minimal example of using useActionState to handle a form submission that updates the name state asynchronously:</p><pre>import React, { useActionState } from &quot;react&quot;;</pre><pre>const Page = () =&gt; {<br>  const [name, submitAction, isPending] = useActionState&lt;string, FormData&gt;(<br>    async (_, formData: FormData): Promise&lt;string&gt; =&gt; {<br>      const newName = formData.get(&quot;name&quot;) as string;<br>      return newName;<br>    },<br>    &quot; &quot; // initial value of name<br>  );<br>  return (<br>    &lt;&gt;<br>      &lt;p&gt;Current user: {name}&lt;/p&gt;</pre><pre>&lt;form action={submitAction}&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;Enter your name&quot; /&gt;<br>        &lt;button type=&quot;submit&quot; disabled={isPending}&gt;<br>          {isPending ? &quot;Submitting...&quot; : &quot;Submit&quot;}<br>        &lt;/button&gt;<br>      &lt;/form&gt;<br>    &lt;/&gt;<br>  );<br>};</pre><p>Here’s what’s happening:</p><ul><li>The useActionState hook manages the name state, the submit handler, and the loading (isPending) flag in one place.</li><li>When the form is submitted, useActionState <strong>runs the function and calls the API</strong> (or server action) behind the scenes, handling the async process.</li><li>The UI updates automatically with the submitted name, and the submit button is disabled while waiting, giving a smooth user experience.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68bfaf3432fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>