Skip to content

Commit 368d048

Browse files
Fix missing React hook dependencies
1 parent 833f2cc commit 368d048

File tree

11 files changed

+35
-25
lines changed

11 files changed

+35
-25
lines changed

src/components/content-presentation/table/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const TableComponent = forwardRef<HTMLTableElement, TableProps>((props, forwarde
4545
responsive,
4646
setHeadings,
4747
};
48-
}, [responsive, headings, setHeadings]);
48+
}, [firstCellIsHeader, headings, responsive, setHeadings]);
4949

5050
return (
5151
<TableContext.Provider value={contextValue}>

src/components/content-presentation/table/components/TableRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const TableRow: FC<ComponentPropsWithoutRef<'tr'>> = ({ children, classNa
1818
if (responsive && section === TableSection.HEAD) {
1919
setHeadings(getHeadingsFromChildren(children));
2020
}
21-
}, [responsive, section, children]);
21+
}, [children, responsive, section, setHeadings]);
2222

2323
const tableCells = Children.map(children, (child, index) => {
2424
return section === TableSection.BODY && isTableCell(child)

src/components/form-elements/checkboxes/components/Item.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export const CheckboxesItem = forwardRef<HTMLInputElement, CheckboxesItemProps>(
4141
const { getBoxId, name, leaseReference, unleaseReference } =
4242
useContext<ICheckboxesContext>(CheckboxesContext);
4343

44-
const [boxReference] = useState<string>(leaseReference());
45-
const inputID = id || getBoxId(boxReference);
44+
const [checkboxReference] = useState<string>(leaseReference());
45+
const inputID = id || getBoxId(checkboxReference);
4646
const shouldShowConditional = !!(checked || defaultChecked);
4747

4848
const { className: labelClassName, ...restLabelProps } = labelProps || {};
4949
const { className: hintClassName, ...restHintProps } = hintProps || {};
5050
const { className: conditionalClassName, ...restConditionalProps } = conditionalProps || {};
5151

52-
useEffect(() => () => unleaseReference(boxReference), []);
52+
useEffect(() => () => unleaseReference(checkboxReference));
5353

5454
const inputProps: HTMLAttributesWithData<HTMLInputElement> = rest;
5555

src/components/form-elements/date-input/DateInput.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ const DateInputComponent = forwardRef<HTMLDivElement, DateInputProps>(
5151
});
5252

5353
useEffect(() => {
54-
const newState = { ...internalDate };
55-
const { day, month, year } = value ?? {};
56-
if (day && day !== internalDate.day) newState.day = day;
57-
if (month && month !== internalDate.month) newState.month = month;
58-
if (year && year !== internalDate.year) newState.year = year;
59-
60-
return setInternalDate(newState);
61-
}, [value]);
54+
if (!value) {
55+
return;
56+
}
57+
58+
if (
59+
value.day === internalDate.day &&
60+
value.month === internalDate.month &&
61+
value.year === internalDate.year
62+
) {
63+
return;
64+
}
65+
66+
return setInternalDate({
67+
day: value.day ?? internalDate.day,
68+
month: value.month ?? internalDate.month,
69+
year: value.year ?? internalDate.year,
70+
});
71+
}, [internalDate, value]);
6272

6373
const handleChange = (inputType: InputType, event: ChangeEvent<HTMLInputElement>): void => {
6474
event.stopPropagation();

src/components/form-elements/radios/components/Item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export const RadiosItem = forwardRef<HTMLInputElement, RadiosItemProps>((props,
4747

4848
useEffect(() => {
4949
if (defaultChecked) setSelected(radioReference);
50-
}, []);
50+
}, [defaultChecked, setSelected, radioReference]);
5151

5252
useEffect(() => {
5353
if (checked) setSelected(radioReference);
54-
}, [checked]);
54+
}, [checked, setSelected, radioReference]);
5555

5656
return (
5757
<>

src/components/navigation/header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const HeaderComponent = forwardRef<HTMLElement, HeaderProps>((props, forwardedRe
106106
setServiceProps,
107107
setOrganisationProps,
108108
};
109-
}, [logoProps, serviceProps, organisationProps]);
109+
}, [logoProps, serviceProps, organisationProps, menuOpen]);
110110

111111
const items = Children.toArray(children);
112112
const childLogo = items.find((child) => childIsOfComponentType(child, Logo));

src/components/navigation/header/components/Logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const Logo: FC<LogoProps> = (logo) => {
1414

1515
setLogoProps(logo);
1616
return () => setLogoProps(undefined);
17-
}, [logo]);
17+
}, [logo, setLogoProps]);
1818

1919
const { alt = 'NHS' } = logo;
2020

src/components/navigation/header/components/Navigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Navigation: FC<NavigationProps> = ({
2626

2727
setMenuOpen(open);
2828
return () => setMenuOpen(false);
29-
}, [open]);
29+
}, [open, setMenuOpen]);
3030

3131
return (
3232
<nav

src/components/utils/FormGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ export const FormGroup = <T extends BaseFormElementRenderProps>(
104104
useEffect(() => {
105105
passError(elementID, disableErrorFromComponents ? false : Boolean(error));
106106
return () => passError(elementID, false);
107-
}, [elementID, error]);
107+
}, [disableErrorFromComponents, elementID, error, passError]);
108108

109109
useEffect(() => {
110110
registerComponent(elementID);
111111
return () => registerComponent(elementID, true);
112-
}, []);
112+
}, [elementID, registerComponent]);
113113

114114
return (
115115
<div

src/util/hooks/UseDevWarning.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export const useDevWarning = (warning: string, condition: ConditionFn = () => tr
99
// eslint-disable-next-line no-console
1010
console.warn(warning);
1111
}
12-
}, [warning]);
12+
}, [warning, condition]);
1313
};

0 commit comments

Comments
 (0)