Skip to content
Discussion options

You must be logged in to vote

Take for instance:

"use client";
import { useTransition } from "react";

import { useRouter } from "next/navigation";

export function CreatePost() {
  const router = useRouter();
  const [isPending, startTransition] = useTransition();

  const addPost = trpc.post.add.useMutation({
    async onSuccess(_input, output) {
      startTransition(() => {
        router.push(`/post/${output.id}`);
      });
    },
  });

  return (
    <form
      onSubmit={() => {
        addPost.mutate({
          text: "123",
        });
      }}
    >
      <input type="submit" disabled={addPost.isMutating || isPending} />
    </form>
  );
}

So as the route transition is batched, you start a pending transiti…

Replies: 3 comments 12 replies

Comment options

You must be logged in to vote
11 replies
@icyJoseph
Comment options

@devjiwonchoi
Comment options

@codinginflow
Comment options

@icyJoseph
Comment options

Answer selected by codinginflow
@codinginflow
Comment options

@icyJoseph
Comment options

@codinginflow
Comment options

@icyJoseph
Comment options

Comment options

You must be logged in to vote
1 reply
@ptts
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants