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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @reergymerej

        Issue actions

          [Typo]: example code contradicts other `startTransition` examples · Issue #7444 · reactjs/react.dev