reactjs - Do 'Actions' in React 19 include synchronous transitions? - Stack Overflow

admin2025-05-02  1

I recently read some documents and official blog posting about react 19, and got confused about exact definition of 'Actions'.

In official blog post 'Actions' is defined as below;

By convention, functions that use async transitions are called “Actions”

But in official documentation for useTransition, 'Actions' is defined as below;

Functions called in startTransition are called “Actions”.

What confuses me at this point is whether functions that use 'synchronous transitions', as shown below, can also be called 'Actions.'

const [searchQuery, setSearchQuery] = useState();
const [isPending, startTransition] = useTransition();

startTransition(() => {
  setSearchQuery(input);
});

I recently read some documents and official blog posting about react 19, and got confused about exact definition of 'Actions'.

In official blog post 'Actions' is defined as below;

By convention, functions that use async transitions are called “Actions”

But in official documentation for useTransition, 'Actions' is defined as below;

Functions called in startTransition are called “Actions”.

What confuses me at this point is whether functions that use 'synchronous transitions', as shown below, can also be called 'Actions.'

const [searchQuery, setSearchQuery] = useState();
const [isPending, startTransition] = useTransition();

startTransition(() => {
  setSearchQuery(input);
});
Share Improve this question edited Jan 2 at 9:55 piecemaker asked Jan 2 at 4:49 piecemakerpiecemaker 735 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, normal synchronous Javascript functions (ie. ones without the async character) are valid actions. The blog post you're referring to is announcing that async functions are now supported, but regular function support wasn't removed.

For instance, if you follow the link in the blog to the definition of useActionState you will see that it doesn't require an async function:

fn: The function to be called when the form is submitted or button pressed. When the function is called, it will receive the previous state of the form (initially the initialState that you pass, subsequently its previous return value) as its initial argument, followed by the arguments that a form action normally receives.

转载请注明原文地址:http://www.anycun.com/QandA/1746134052a92046.html