main
js 37 lines 632 Bytes
Raw
1 'use client';
2
3 import * as React from 'react';
4 import {useFormStatus} from 'react-dom';
5 import ErrorBoundary from './ErrorBoundary.js';
6
7 const h = React.createElement;
8
9 function ButtonDisabledWhilePending({action, children}) {
10 const {pending} = useFormStatus();
11 return h(
12 'button',
13 {
14 disabled: pending,
15 formAction: action,
16 },
17 children
18 );
19 }
20
21 export default function Button({action, children}) {
22 return h(
23 ErrorBoundary,
24 null,
25 h(
26 'form',
27 null,
28 h(
29 ButtonDisabledWhilePending,
30 {
31 action: action,
32 },
33 children
34 )
35 )
36 );
37 }