| 1 | 'use client'; |
| 2 | |
| 3 | import {useFormStatus} from 'react-dom'; |
| 4 | import ErrorBoundary from './ErrorBoundary.js'; |
| 5 | |
| 6 | function ButtonDisabledWhilePending({action, children}) { |
| 7 | const {pending} = useFormStatus(); |
| 8 | return ( |
| 9 | <button disabled={pending} formAction={action}> |
| 10 | {children} |
| 11 | </button> |
| 12 | ); |
| 13 | } |
| 14 | |
| 15 | export default function Button({action, children}) { |
| 16 | return ( |
| 17 | <ErrorBoundary> |
| 18 | <form> |
| 19 | <ButtonDisabledWhilePending action={action}> |
| 20 | {children} |
| 21 | </ButtonDisabledWhilePending> |
| 22 | </form> |
| 23 | </ErrorBoundary> |
| 24 | ); |
| 25 | } |