From 35b8db18dfc3c30fcb0611bdcc94453af47b6d30 Mon Sep 17 00:00:00 2001 From: MorikawaSouma Date: Wed, 18 Mar 2026 12:48:44 +0800 Subject: [PATCH] docs(eslint-plugin-react-hooks): fix misleading additionalHooks regex example The previous regex example without anchors would match unintended hook names. For example, (useMyCustomHook|useMyOtherCustomHook) would also match useMyCustomHook2 and useMyOtherCustomHookTest. Added anchors (^ and $) to ensure exact matching and added a note explaining the importance of using anchors. Fixes #29045 --- packages/eslint-plugin-react-hooks/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/README.md b/packages/eslint-plugin-react-hooks/README.md index a1b4bcabb59f..dcb3109c0ae2 100644 --- a/packages/eslint-plugin-react-hooks/README.md +++ b/packages/eslint-plugin-react-hooks/README.md @@ -135,12 +135,14 @@ This option accepts a regex to match the names of custom Hooks that have depende rules: { // ... "react-hooks/exhaustive-deps": ["warn", { - additionalHooks: "(useMyCustomHook|useMyOtherCustomHook)" + additionalHooks: "^(useMyCustomHook|useMyOtherCustomHook)$" }] } } ``` +**Note:** The regex should use anchors (`^` and `$`) to ensure exact matching. Without anchors, the pattern `(useMyCustomHook|useMyOtherCustomHook)` would also match `useMyCustomHook2` or `useMyOtherCustomHookTest`. + We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks to not use the dependencies argument, and instead provide a higher-level API that is more focused around a specific use case. ## Valid and Invalid Examples