From 5f744e83cf68456bc9e5590dcd754ca1cbf81e76 Mon Sep 17 00:00:00 2001 From: chirokas <157580465+chirokas@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:34:48 +0800 Subject: [PATCH] `no-useless-undefined`: Ignore React 19 `useRef` calls (#2463) --- rules/no-useless-undefined.js | 2 ++ test/no-useless-undefined.mjs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rules/no-useless-undefined.js b/rules/no-useless-undefined.js index 4a24698a6a..8239bcba9f 100644 --- a/rules/no-useless-undefined.js +++ b/rules/no-useless-undefined.js @@ -62,6 +62,8 @@ const shouldIgnore = node => { || name === 'createContext' // `setState(undefined)` || /^set[A-Z]/.test(name) + // React 19 useRef + || name === 'useRef' // https://vuejs.org/api/reactivity-core.html#ref || name === 'ref'; diff --git a/test/no-useless-undefined.mjs b/test/no-useless-undefined.mjs index c95c7dde35..fd10559916 100644 --- a/test/no-useless-undefined.mjs +++ b/test/no-useless-undefined.mjs @@ -53,6 +53,8 @@ test({ 'array.unshift(undefined);', 'createContext(undefined);', 'React.createContext(undefined);', + 'useRef(undefined);', + 'React.useRef(undefined);', 'setState(undefined)', 'setState?.(undefined)', 'props.setState(undefined)',