Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

draft-input.tsx

13 lines530 Bytes

1import { useCommitOnBlur } from "~/hooks/useCommitOnBlur";
2import { Input, type InputProps } from "./input";
3​
4export type DraftInputProps = Omit<InputProps, "value" | "onChange" | "defaultValue"> & {
5 readonly value: string;
6 readonly onCommit: (next: string) => void;
7};
8​
9/** Commit drafts without settings-wide rerenders or server round trips per keystroke. */
10export function DraftInput({ value, onCommit, ...rest }: DraftInputProps) {
11 const bag = useCommitOnBlur(value, onCommit);
12 return <Input {...rest} {...bag} />;