Skip to content

Commit 6fff943

Browse files
committed
fix: allows to use form field error outside of form field
1 parent 8b5e224 commit 6fff943

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/components/form/form-field-error.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212

1313
import { cn } from '@/lib/tailwind/utils';
1414

15-
import { useFormField } from '@/components/form/form-field';
15+
import { useFormFieldUnsafe } from '@/components/form/form-field';
1616

1717
import {
1818
FormFieldControllerContext,
@@ -38,7 +38,7 @@ export const FormFieldError = <
3838
children,
3939
...props
4040
}: FormFieldErrorProps<TFieldValues, TName>) => {
41-
const fieldCtx = useFormField();
41+
const fieldCtx = useFormFieldUnsafe();
4242
const controllerCtx = use<FormFieldControllerContextValue<
4343
TFieldValues,
4444
TName
@@ -81,7 +81,7 @@ export const FormFieldError = <
8181

8282
return (
8383
<div
84-
id={fieldCtx.errorId}
84+
id={fieldCtx?.errorId}
8585
className={cn(
8686
'flex animate-in gap-1 text-sm text-negative-600 slide-in-from-top-1 dark:text-negative-400',
8787
className

app/components/form/form-field.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ export const useFormField = () => {
5454
}
5555
return fieldContext;
5656
};
57+
58+
export const useFormFieldUnsafe = () => {
59+
return use(FormFieldContext);
60+
};

0 commit comments

Comments
 (0)