Skip to content

Commit

Permalink
Make sure wasFieldTouched and isErrorVisible use useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesuss committed Nov 20, 2020
1 parent 348dd80 commit e662c34
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/FormErrorState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ export const FormErrorState: React.FunctionComponent<FormErrorStateProps> = ({
return error;
}, callbackRegenValues);

const wasFieldTouched = (id: string) => blurredFieldIds.has(id) || didAttemptSubmission;
const isErrorVisible = (id: string) => wasFieldTouched(id) && erroredFieldIds.has(id);
const wasFieldTouched = useCallback(
(id: string) => blurredFieldIds.has(id) || didAttemptSubmission,
callbackRegenValues
);

const isErrorVisible = useCallback(
(id: string) => wasFieldTouched(id) && erroredFieldIds.has(id),
callbackRegenValues
);

const onFocus = useCallback((id: string) => setFocusedFieldId(id), []);

Expand Down

0 comments on commit e662c34

Please sign in to comment.