Best way to redirect from create page back to index

Looking for some guidance around best practice to handle form create and redirects in one step. I often only see examples of create>invalidate on the same page but haven't come across many where there is a dedicated next page for the create form that redirects to another page.

Currently, I have this setup something like this:

 const router = useRouter();

  const { mutate, isLoading: isPosting } = api.example.create.useMutation({
    onSuccess: () => {
      setInput("");
      void ctx.example.getAll.invalidate();
      router.push("/");
    },
  });


However, I am not sure that this pattern makes sense or if there is a more correct / efficient way to do this (for example waiting for the outcome of the create and sending this as props)?

Any example projects or guidance would be super helpful.
Was this page helpful?