Skip to content

Commit 6ef7938

Browse files
Fix scroll-to-error hook null reference error
- Add null check in useScrollToErrorOnSubmit hook to prevent 'Cannot read properties of null (reading handleSubmit)' error - Remove duplicate ScrollToErrorComponentExample component declaration - Hook now gracefully handles cases where no form methods are available - Adds warning message when form context is missing
1 parent 693054d commit 6ef7938

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

packages/components/src/remix-hook-form/hooks/useScrollToErrorOnSubmit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export const useScrollToErrorOnSubmit = (options: UseScrollToErrorOnSubmitOption
1616
const contextMethods = useRemixFormContext();
1717
const { methods, delay = 100, enabled = true, scrollOnServerErrors = true, scrollOnMount = true, ...scrollOptions } = options;
1818
const formMethods = methods || contextMethods;
19+
20+
// Early return if no form methods are available
21+
if (!formMethods) {
22+
console.warn('useScrollToErrorOnSubmit: No form methods available. Make sure you are either inside a RemixFormProvider or passing methods explicitly.');
23+
return;
24+
}
25+
1926
const { formState } = formMethods;
2027

2128
// Memoize scroll options to prevent unnecessary re-renders

0 commit comments

Comments
 (0)