You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: ESLint flags just refering (not calling) functions that use refs as accessing refs (react-hooks/refs) #37521
12:7 error Error: Cannot access refs during render
React refs are values that are not needed for rendering. Refs should only be accessed outside of render, such as in event handlers or effects. Accessing a ref value (the `current` property) during render can cause your component not to update as expected (https://react.dev/reference/react/useRef).
C:\MyApps\temp\next-read-function-using-ref-in-render\app\page.tsx:12:7
10 |
11 | const [prevSampleFunc, setPrevSampleFunc] = useState<(() => void) | null>(null);
> 12 | if (sampleFunc !== prevSampleFunc) {
| ^^^^^^^^^^ Cannot access ref value during render
13 | setPrevSampleFunc(() => sampleFunc);
14 | }
15 | react-hooks/refs
The expected behavior
In this code, the function sampleFunc is just referred and not called during render.
Therefore, I don't think that this code is accessing refs during render as the error message suggests.
I expect this message, which looks like a false positive, isn't emitted for this code.
Activity
[compiler] Don't treat comparing a ref-reading function as a ref access
[compiler] Don't treat comparing a ref-reading function as a ref access
[compiler] Don't treat comparing a ref-reading function as a ref acce…