Skip to content

Commit 0e10ad7

Browse files
committed
Add eslint-disable directives for rules-of-hooks
1 parent c53e435 commit 0e10ad7

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1+
import { useCallback, useMemo } from 'react';
12
import { useNavigate } from 'react-router-dom-v5-compat';
23
import { parseMetaMaskUrl } from '@metamask/snaps-utils';
34
import { getSnapRoute } from '../../helpers/utils/util';
45

56
const useSnapNavigation = () => {
67
const navigate = useNavigate();
7-
const useSnapNavigate = (url: string) => {
8-
let path;
9-
const linkData = parseMetaMaskUrl(url);
10-
if (linkData.snapId) {
11-
path = getSnapRoute(linkData.snapId);
12-
} else {
13-
path = linkData.path;
14-
}
15-
navigate(path);
16-
};
17-
return {
18-
useSnapNavigate,
19-
};
8+
const useSnapNavigate = useCallback(
9+
(url: string) => {
10+
let path;
11+
const linkData = parseMetaMaskUrl(url);
12+
if (linkData.snapId) {
13+
path = getSnapRoute(linkData.snapId);
14+
} else {
15+
path = linkData.path;
16+
}
17+
navigate(path);
18+
},
19+
[navigate],
20+
);
21+
return useMemo(
22+
() => ({
23+
useSnapNavigate,
24+
}),
25+
[useSnapNavigate],
26+
);
2027
};
2128

2229
export default useSnapNavigation;

ui/pages/confirmations/components/confirm/info/hooks/useNestedTransactionLabels.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function useNestedTransactionLabels({
1515
const { data, to } = nestedTransaction;
1616
// It's safe to call useFourByte here because the length of nestedTransactions
1717
// remains stable throughout the component's lifecycle.
18+
// eslint-disable-next-line react-hooks/rules-of-hooks
1819
const methodData = useFourByte({ data, to });
1920
const functionName = methodData?.name;
2021

ui/pages/notifications/notification-components/snap/snap-footer-button.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const SnapFooterButton = (props: { notification: SnapNotification }) => {
4444
if (isExternal) {
4545
setIsOpen(true);
4646
} else {
47+
// This hook is safe to include in this event handler, because its only reactive component is `useNavigate`
48+
// eslint-disable-next-line react-hooks/rules-of-hooks
4749
useSnapNavigate(href);
4850
}
4951
},

0 commit comments

Comments
 (0)