Submit Button

PreviousNext

Enhanced submit button with loading state that automatically detects form submission state using React's useFormStatus hook.

Installation

pnpm dlx shadcn@latest add https://ui.nowts.app/r/submit-button.json

Usage

The SubmitButton automatically detects form submission state using React's useFormStatus hook. It shows a loading spinner during form submission.

import { SubmitButton } from "@/components/ui/submit-button"
 
export function MyForm() {
  return (
    <form action={serverAction}>
      <input name="email" type="email" />
      <SubmitButton>Submit</SubmitButton>
    </form>
  )
}

With ExtendedForm

The button works seamlessly with ExtendedForm for client-side validation:

import { z } from "zod"
 
import { ExtendedForm, useZodForm } from "@/components/ui/extended-form"
import { SubmitButton } from "@/components/ui/submit-button"
 
const schema = z.object({
  email: z.string().email(),
})
 
export function MyForm() {
  const form = useZodForm({ schema })
 
  return (
    <ExtendedForm
      form={form}
      onSubmit={async (data) => {
        // Form submission
      }}
    >
      <input {...form.register("email")} />
      <SubmitButton>Submit</SubmitButton>
    </ExtendedForm>
  )
}

LoadingButton Variant

You can also use LoadingButton for manual control of the loading state:

import { LoadingButton } from "@/components/ui/submit-button"
 
export function MyButton() {
  const [isLoading, setIsLoading] = useState(false)
 
  return (
    <LoadingButton loading={isLoading} onClick={handleClick}>
      Click Me
    </LoadingButton>
  )
}

Props

SubmitButton

Accepts all props from Button component from shadcn/ui.

LoadingButton

PropTypeDefaultDescription
loadingbooleanfalseControls the loading state
...buttonPropsButtonProps-All button props are forwarded