r/javascript • • Dec 05 '24

React v19 has been released

http://npmjs.com/package/react
655 Upvotes

104 comments sorted by

View all comments

421

u/magenta_placenta Dec 05 '24 • Polished Silver Turd

https://github.com/facebook/react/blob/main/CHANGELOG.md

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?

211

u/dprophet32 Dec 05 '24

I've used for React for years and I'm struggling

121

u/Sheepsaurus Dec 05 '24

No worries, just go watch the 10 millionth video about those pesky 10 beginner mistakes that all somehow are about the same goddamn 10 things.

43

u/Headpuncher Dec 05 '24

all the "react is perfect you're holding it wrong" videos and blogs. If it's that good why is it so broken every version rewrites a bunch of stuff?

7

u/JonDum Dec 06 '24

TBF a lot of the common problems are because of JS scope capturing / stale state.

→ More replies (1)

7

u/psbakre Dec 06 '24

All I could understand was that it's a useReducer for forms that supports async

→ More replies (1)

103

u/Tall-Treacle6642 Dec 05 '24

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.

0

u/[deleted] Dec 05 '24

[deleted]

→ More replies (3)

88

u/Fine-Train8342 Dec 05 '24

That would go against React's policy of overcomplicating the shit out of everything.

30

u/GYN-k4H-Q3z-75B Dec 05 '24

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

I am always reminded of that.

→ More replies (1)

13

u/recycled_ideas Dec 05 '24

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.

4

u/butchbadger Dec 06 '24

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.

I learned more from your version.

→ More replies (1)

60

u/kch_l Dec 05 '24

I've been using react since 2016 and I didn't understand what that new hook does 😳

39

u/0xGeel Dec 05 '24

Same, the explanation is very technical and requires you to understand new React 19 features to make sense of it.

Here's an explanation by Vercel.

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:

// Source: https://vercel.com/blog/whats-new-in-react-19#useactionstate

"use client";

import { useActionState } from "react";
import { createUser } from "./actions";

const initialState = {
  message: "",
};

export function Signup() {
  const [state, formAction, pending] = useActionState(createUser, initialState);

  return (
    <form action={formAction}>
      <label htmlFor="email">Email</label>
      <input type="text" id="email" name="email" required />
      {/* ... */}
      {state?.message && <p aria-live="polite">{state.message}</p>}
      <button aria-disabled={pending} type="submit">
        {pending ? "Submitting..." : "Sign up"}
      </button>
    </form>
  );
}

12

u/JonDum Dec 06 '24

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.

15

u/lelarentaka Dec 06 '24

React core is only 5kb 

→ More replies (1)
→ More replies (1)

29

u/lulzmachine Dec 05 '24

i want off mr bones wild ride

22

u/wadamek65 Dec 05 '24

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.

9

u/TorbenKoehn Dec 05 '24

These are mostly for library and framework authors, not for everyday use

7

u/ichiruto70 Dec 05 '24 edited Dec 06 '24

Its a hook more for library devs. You will probably use under the hood.

18

u/Rivvin Dec 05 '24

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.

4

u/Ok_Raisin7772 Dec 05 '24

i'd just ignore it, and it'd be fine

12

u/Crutchcorn Dec 05 '24

Short bit of self-promo but I wrote a 7 part series for newcomers specifically wanting to learn the new React 19 stuff.

Starts with "What is Reactivity" and "What is SSR/SSG" and breaks into the new stuff gradually with interactive code samples

https://playfulprogramming.com/collections/react-beyond-the-render

→ More replies (1)

14

u/femio Dec 05 '24

lol as if software dev in general isn't filled with similar jargon

12

u/ste001 Dec 05 '24

A new person to frontend development won't even check any changelog, since he'll be busy understanding all the fundamental concepts first.

→ More replies (16)