aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/submit-button.tsx
blob: 7489c6ca87f1dda7df0e23379565549a476220dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Button } from '@/components/ui/button'
import { Loader2 } from 'lucide-react'
import { PropsWithChildren, ReactNode } from 'react'
import { useFormState } from 'react-hook-form'

type Props = PropsWithChildren<{
  loadingContent: ReactNode
}>

export function SubmitButton({ children, loadingContent }: Props) {
  const { isSubmitting } = useFormState()
  return (
    <Button type="submit" disabled={isSubmitting}>
      {isSubmitting ? (
        <>
          <Loader2 className="w-4 h-4 mr-2 animate-spin" /> {loadingContent}
        </>
      ) : (
        children
      )}
    </Button>
  )
}