17 lines
725 B
TypeScript
17 lines
725 B
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { useFormStatus } from "react-dom";
|
|
|
|
/**
|
|
* PEP-146: the <button> behind every `Button`. While the server action of its form is running
|
|
* it cannot be pressed again — a second click used to send the same form twice and the second
|
|
* request answered with an error («уже занят», «уже обновляется»). Outside a form, and for
|
|
* `type="button"`, nothing changes.
|
|
*/
|
|
export function FormButton({ disabled, type, ...props }: React.ComponentProps<"button">) {
|
|
const { pending } = useFormStatus();
|
|
const busy = pending && type !== "button";
|
|
return <button type={type} disabled={disabled || busy} aria-busy={busy || undefined} {...props} />;
|
|
}
|