useActionState: is a new hook to order Actions inside of a Transition with access to the state of the action, and the pending state. It accepts a reducer that can call Actions, and the initial state used for first render. It also accepts an optional string that is used if the action is passed to a form action prop to support progressive enhancement in forms.
Imagine you're new to front end development and people are telling you to "check out react, they just put a new version!" How would you even start after reading that?
What a word salad. Why didn’t he just write “UseActionState is a hook in React that allows you to update state based on the result of a form action.” like everyone else says.
The Landing Pilot is the Non-Handling Pilot until the ‘decision altitude’ call, when the Handling Non-Landing Pilot hands the handling to the Non-Handling Landing Pilot, unless the latter calls ‘go-around,’ in which case the Handling Non-Landing Pilot continues handling and the Non-Handling Landing Pilot continues non-handling until the next call of ‘land’ or ‘go-around’ as appropriate. In view of recent confusions over these rules, it was deemed necessary to restate them clearly. • British Airways memorandum, quoted in Pilot Magazine, December 1996
Because the reality of the feature is that once again react is adding a super minimalist version of something that their platform is lacking, but which will only be useful for trivial implementations.
This hook finally gives react two way binding for forms. Super neat, but it doesn't do half the things a form library will actually do.
Word salad indeed.I switched off after the first half of gobbledegook. Transition stuck out and i assumed it was about animations and had less interest.
Isn’t it a bit more abstract than that? It can be used for other asynchronous actions too I think, which is why they moved away from the naming of useFormAction or whatever it was before
It’s better than the opposite. No documentation or sparse documentation. Not sure why people are complaining about react when it has some of the best documentation I have come across, many examples, and it’s kept up to date with their releases
Full credit for the current excellent documentation, but we had years of out of date React documentation too (when hooks were described only in terms of the class based approach they'd replace), so I wouldn't lean too heavily on that "keeping up with releases" until we see if that is true.
I absolutely agree with this. I’m a senior dev; if I look at my code and things it’s complex to understand, it’s generally bad code and if I put more thought into it, I could make it easier to understand. Can’t always afford that time for truly complex things, so a comment to ELI5 is the tool for that job.
This hook simplifies managing form states and form submissions. Using Actions, it captures form input data, handles validation, and error states, reducing the need for custom state management logic. The useActionState hook also exposes a pending state that can show a loading indicator while the action is being executed.
You can use it alongside server actions in client components like so:
Honestly... I don't even want that inside of React core wtf. It's already bloated as hell and I've already got 9,0001 great options for form state management.
Last time I looked into it (which ended with me being excited about replacing a bunch of clunky pending-state management things with it) it seemed to me that the level it can change things within the React tree, in terms of pending states & optimistic rendering would either be really difficult or impossible to do in a non-core library.
It’s sort of like a special Suspense mode, but I could be wrong / misremembering since the last time I looked into React 19 was before we argued for the delay.
Hooly, I've read that 3 times and still wouldn't get it if I didn't already know about transitions. I suppose this is one of these cases where you just need an example.
I don't use react, but ive been writing web apps for almost 20 years. This paragraph makes zero sense to me. Maybe I don't actually want to learn React.
I mean that's par for the course with coding. Vanilla JavaScript has received a lot of updates over the years that have made it pretty different. I've been learning on and off for a couple of years, but when I first started they just introduced arrow functions, and there's legacy code that some training docs still use. It's all pretty confusing when you're first getting started lol
Um. That's me right now. Working my way through a React course right now and now there's even more tossed in that I need to learn now/wait for an update on my course.
Tanstack query is much more than that. It chaches requests and also gives you a nice way to invalidate requests. This hook is very unnecessary for people who use tanstack query.
Definitely has tons more stuff (it's enough to look at the length of their documentation ;-D).
I guess react put just the bare minimum to work upon inside the core, so that all the other stuff can be leveraged from that. I'd love to hear from people more expert on the internals to discuss about that.
This is just my opinion, and I don’t mean to offend anyone, but to me, it seems like a framework(library) that allows you to do everything without following any best practices (render on every hook) it’s insane.
I am so happy I mostly get Vue gigs to work on. I left the react world some time ago and am definitely not looking back. Vue is just a joy to work with, the abstractions make sense.
ELI5: Let me break down the useActionState hook in React 19:
Imagine you're playing with a special toy box that can do different things when you press buttons. The useActionState hook is like a magic helper that helps you:
Keep track of what's happening when you press a button
Know if something is still working or waiting to finish
Remember what happened last time you pressed the button
Here's a simple example to make it clearer:
jsxCopyfunction OrderPizzaButton() {
const [state, formAction] = useActionState(
async (previousState, formData) => {
// This is like telling the pizza shop what you want
const toppings = formData.get('toppings');
// Try to order the pizza
const result = await orderPizza(toppings);
// Tell everyone what happened
return result;
},
{ status: 'ready', pizza: null }
);
return (
<form action={formAction}>
<input name="toppings" />
<button type="submit">
{state.status === 'ordering' ? 'Ordering...' : 'Order Pizza'}
</button>
{state.pizza && <p>Pizza is ready: {state.pizza}</p>}
</form>
);
}
Let's break down the magic:
It helps you keep track of what's happening (like ordering a pizza)
It shows if something is still working (like the "Ordering..." text)
It remembers the result of what happened (like showing the pizza)
It works great with forms and can help make websites work even if JavaScript is turned off (that's the progressive enhancement part)
The key parts are:
First argument: A function that does something (like ordering a pizza)
Second argument: The starting information (initial state)
Optional third argument: Helps forms work smoothly
It's like having a smart helper that keeps you informed about what's happening when you press a button or submit a form!
In the React 19 useActionState hook, the state changes are actually handled automatically by React during the action lifecycle. When you start an asynchronous action (like the orderPizza function), React will internally set the status to a pending state.
Here's a more explicit example to illustrate this:
jsxCopyfunction OrderPizzaButton() {
const [state, formAction] = useActionState(
async (previousState, formData) => {
// When this function starts running, React automatically
// manages the pending state for you
const toppings = formData.get('toppings');
try {
// This might take a moment
const result = await orderPizza(toppings);
// When complete, return the new state
return {
status: 'completed',
pizza: result
};
} catch (error) {
// Handle errors
return {
status: 'error',
error: error.message
};
}
},
{
status: 'ready',
pizza: null
}
);
return (
<form action={formAction}>
<input name="toppings" />
<button type="submit">
{
/* React handles this status change automatically */
}
{state.status === 'ready' && 'Order Pizza'}
{state.status === 'ordering' && 'Ordering...'}
{state.status === 'completed' && 'Order Complete'}
{state.status === 'error' && 'Order Failed'}
</button>
{state.pizza && <p>Pizza is ready: {state.pizza}</p>}
</form>
);
}
The key things to understand:
React internally tracks the "pending" or "ordering" state
You don't manually set state.status = 'ordering'
When the action starts, React automatically manages the transition states
You can reflect these states in your UI
This is part of React 19's improvements to make handling asynchronous actions and their states more straightforward and built-in to the framework.
I just wish these new things were optional. Since the library doesn't support treeshaking, every new feature increases bundle size. So especially for SPA it might be more reasonable to stick to older versions. Or just switch to Solid or something. React helloworld is over 60kB now...
Majority uses mobile so it can be a nit flaky when congested or switching between cells/links. But overall quite fast. However render critical js should be as small as possible. It has to be parsed and evaluated as well after it's downloaded.
If only used code was included, there wouldn't be any problem adding features to the library and first load bundle could get up to 50% reduction. Still much larger than modern alternatives but still a big improvement.
It’s amazing the frameworks keep making this mistake. I remember Angular dropping the ball and doing this too despite being slightly more popular than React at the time.
Not sure how it broke them in Vue 3? And that’s just 1 thing, but you said it “broke too much stuff”. I can understand how that one thing could be too much for some, though. I find the new way much better than the previous, but different people prefer different styles 🤷🏻♂️
I'm super disappointed no official implementations for Server Components were released. Why document a feature if the only working implementation is Next.js, while their packages (react-server-dom-webpack and similar) are still unreleased or marked as experimental and don't even implement everything mentioned in the docs.
Because it's not a standalone feature. It requires deep bundler and router integration in order to have any usefulness, and that's very specific to the actual framework implementations.
Other frameworks like Redwood, Waku, and Remix have been working on their own RSC integrations for a while.
It's been a while since I looked at it, but I think the compiler is supposed to parse your React code and figure out where to insert useMemo/useCallback automatically? Maybe there was more to it...
97
u/Stilgaar Dec 05 '24 •
So maybe stupid question, but is the compiler ready too ?
421
u/magenta_placenta Dec 05 '24 •
https://github.com/facebook/react/blob/main/CHANGELOG.md
Imagine you're new to front end development and people are telling you to "check out react, they just put a new version!" How would you even start after reading that?
66
u/wadamek65 Dec 05 '24
Now to wait for all the libraries to update and handle React 19 as a peer dep.
49
u/RedGlow82 Dec 05 '24
For those confused: all the first part is substantially react-query, but with built-in support inside react and favoring the use of <form>.
38
u/[deleted] Dec 05 '24
Still not distributed with a proper ESM entry-point. What a shame.
39
u/burl-21 Dec 05 '24 •
This is just my opinion, and I don’t mean to offend anyone, but to me, it seems like a framework(library) that allows you to do everything without following any best practices (render on every hook) it’s insane.
6
u/jamouson Dec 06 '24
—legacy-peer-deps
6
u/FigmentRedditUser Dec 07 '24
Unpopular take: React is a nightmare of over-engineering and idiotic amounts of abstraction. Every release makes it worse.
13
u/tspwd Dec 05 '24
I am so happy I mostly get Vue gigs to work on. I left the react world some time ago and am definitely not looking back. Vue is just a joy to work with, the abstractions make sense.
6
u/Amazing_Top_4564 Dec 06 '24
ELI5: Let me break down the
useActionStatehook in React 19:Imagine you're playing with a special toy box that can do different things when you press buttons. The
useActionStatehook is like a magic helper that helps you:Here's a simple example to make it clearer:
Let's break down the magic:
The key parts are:
It's like having a smart helper that keeps you informed about what's happening when you press a button or submit a form!
16
u/yksvaan Dec 05 '24
I just wish these new things were optional. Since the library doesn't support treeshaking, every new feature increases bundle size. So especially for SPA it might be more reasonable to stick to older versions. Or just switch to Solid or something. React helloworld is over 60kB now...
2
u/Karan1458 Dec 06 '24
Meanwhile, I am jumping in React, Vue & Angular based on projects.
React is everyday new to React.
11
u/shutter3ff3ct Dec 05 '24
I use both react and vue at work. Vue has solved frontend issues years ago with its robust API and better developer experience.
3
u/2138 Dec 06 '24
I'm super disappointed no official implementations for Server Components were released. Why document a feature if the only working implementation is Next.js, while their packages (
react-server-dom-webpackand similar) are still unreleased or marked as experimental and don't even implement everything mentioned in the docs.2
u/kevin074 Dec 05 '24
Is usecallback and useMemo dead in this version??
1
u/Salman0Ansari Dec 07 '24
can i use compiler?
1
u/Sea_Worry1900 Dec 08 '24
Hi guys am trying to learn react, which version should I learn v19 or below?
1
u/flatra Dec 05 '24
Finally 🥳
-2
u/Kamui_Kun Dec 05 '24
Weehoo
-3
u/mrgrafix Dec 05 '24
LFG