Skip to content

[Typo]: example code contradicts other startTransition examples #7444

@reergymerej

Description

@reergymerej

Summary

The example action code in startTransition needs another startTransition in order to handle the await per this limitation.

Page

https://react.dev/reference/rsc/server-functions#server-functions-with-actions

Details

set functions following await inside startTransition need to be wrapped in another startTransition to be handled correctly.

Current

    startTransition(async () => {
      const {error} = await updateName(name);
      // TODO: wrap `set` functions in another `startTransition`
      if (!error) {
        setError(error);
      } else {
        setName('');
      }
    })

Fixed

    startTransition(async () => {
      const {error} = await updateName(name);
      startTransition(() => {
        if (!error) {
          setError(error);
        } else {
          setName('');
        }
      })
    })

Admittedly, this may make the example less clear. As an alternative, maybe include a mention of the correct way to use await and marking subsequent state updates as Transitions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions