Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce react-hooks/exhaustive-deps #9516

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions applications/browser-extension/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ module.exports = {
"error",
{ ignore: ["eslint-enable"] },
],
"react-hooks/exhaustive-deps": [
"error",
{
// Can't add useAsyncEffect to the additionalHooks property because rule complains about passing
// `async` methods to hooks. (Because it's technically non-deterministic in execution order)
// https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md#advanced-configuration
},
],
"jest/valid-title": [
"error",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { type ComponentProps, useCallback } from "react";
import React, { type ComponentProps } from "react";
import { type ComponentMeta, type Story } from "@storybook/react";
import AsyncButton from "./AsyncButton";
import { ModalProvider, useModals } from "@/components/ConfirmationModal";
Expand Down Expand Up @@ -48,17 +48,22 @@ const ChildComponent = ({
cancelCaption,
}: ChildComponentType) => {
const { showConfirmation } = useModals();
const buttonAction = useCallback(async () => {
await showConfirmation({
title,
message,
submitCaption,
cancelCaption,
});
return (
<AsyncButton
onClick={async () => {
await showConfirmation({
title,
message,
submitCaption,
cancelCaption,
});

// Do any action here if confirm === true
}, [showConfirmation]);
return <AsyncButton onClick={buttonAction}>Confirm Modal</AsyncButton>;
// Do any action here if confirm === true
}}
>
Confirm Modal
</AsyncButton>
);
};

const Template: Story<StoryType> = (args) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const ModsPageActions: React.FunctionComponent<{
history,
marketplaceListingUrl,
modId,
editablePackageId,
name,
showDeactivate,
showDelete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ const ModsPageSidebar: React.VoidFunctionComponent<ModsPageSidebarProps> = ({
if (debouncedSearchInput) {
setActiveTab(MODS_PAGE_TABS.all);
}
}, [globalFilter, debouncedSearchInput, setActiveTab, setGlobalFilter]);
}, [
globalFilter,
debouncedSearchInput,
setActiveTab,
setSearchQuery,
setGlobalFilter,
]);

return (
<div className={styles.root}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const GridView: React.VoidFunctionComponent<ModsPageContentProps> = ({
// Re-render the list when expandedRows changes.
useEffect(() => {
listRef.current?.resetAfterIndex(0);
}, [expandedGridRows, columnCount]);
}, [listRef, expandedGridRows, columnCount]);

const GridRow = useCallback(
({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const useScrollIntoViewEffect = (elementName: string, isActive: boolean) => {
scrollIntoView,
);
};
}, []);
}, [elementName, isActive]);

return elementRef;
};
Expand Down
Loading