The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: `react-hook-form` best practices (#44221)
Gildas Garcia5c98bb6c0f31
diff --git a/.cursor/rules/studio/forms/RULE.md b/.cursor/rules/studio/forms/RULE.mdindex b9b729111b5..74f8383f862 100644--- a/.cursor/rules/studio/forms/RULE.md+++ b/.cursor/rules/studio/forms/RULE.md@@ -1,5 +1,5 @@----description: "Studio: form patterns (page layouts + side panels) and react-hook-form conventions"+description: 'Studio: form patterns (page layouts + side panels) and react-hook-form conventions'globs:- apps/studio/**/*.{ts,tsx}alwaysApply: false@@ -29,7 +29,6 @@ Use the Design System UI pattern docs as the source of truth:## Actions and state-- Handle dirty state (`form.formState.isDirty`) to show Cancel and to disable Save.+- Handle dirty state by destructuring `isDirty` from `formState` (`const { isDirty } = form.formState`) then use it to show Cancel and to disable Save.- Show loading on submit buttons via `loading`.- When submit button is outside the `<form>`, set a stable `formId` and use the button’s `form` prop.-diff --git a/apps/design-system/content/docs/ui-patterns/forms.mdx b/apps/design-system/content/docs/ui-patterns/forms.mdxindex 8e02ea0f90f..f37ab471ce9 100644--- a/apps/design-system/content/docs/ui-patterns/forms.mdx+++ b/apps/design-system/content/docs/ui-patterns/forms.mdx@@ -49,7 +49,7 @@ Use the shared [Key/Value Field Array](../fragments/key-value-field-array) fragm4. **Use Cards for grouping**: Wrap form sections in `Card` components with `CardContent` and `CardFooter` for actions.-5. **Handle dirty state**: Show cancel buttons and disable save buttons based on `form.formState.isDirty`.+5. **Handle dirty state**: Show cancel buttons and disable save buttons based on `form.formState.isDirty`. Make sure you destructure `isDirty` from `form.formState` (see https://react-hook-form.com/docs/useform/formstate)6. **Error handling**: Always use mutations with `onSuccess` and `onError` callbacks that show toast notifications.diff --git a/apps/design-system/content/docs/ui-patterns/modality.mdx b/apps/design-system/content/docs/ui-patterns/modality.mdxindex 9c4358cce0c..63938e858f5 100644--- a/apps/design-system/content/docs/ui-patterns/modality.mdx+++ b/apps/design-system/content/docs/ui-patterns/modality.mdx@@ -104,8 +104,13 @@ Studio implementation (preferred in Studio code):import { DiscardChangesConfirmationDialog } from 'components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'import { useConfirmOnClose } from 'hooks/ui/useConfirmOnClose'+const form = useForm(...)+// Always destructure formState values otherwise they won't be updated+// See https://react-hook-form.com/docs/useform/formstate+const { isDirty } = form.formState+const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({- checkIsDirty: () => form.formState.isDirty,+ checkIsDirty: () => isDirty,onClose,})