Skip to content

Bug: ESLint flags just refering (not calling) functions that use refs as accessing refs (react-hooks/refs) #37521

Description

@mikecat

React version: 19.2.8
ESLint version: 9.39.5
Node.js version; 24.20.0

Steps To Reproduce

  1. Run npm run lint command at the root of the repository.

Link to code example: mikecat/next-read-function-using-ref-in-render: Next.js example where just refering (not calling) function that uses refs is marked as accessing refs during render

page.tsx:

import { useCallback, useState, useRef } from 'react';

export default function Home() {
  const [sampleValue, setSampleValue] = useState(0);
  const sampleRef = useRef(0);

  const sampleFunc = useCallback(() => {
    setSampleValue(++sampleRef.current);
  }, []);

  const [prevSampleFunc, setPrevSampleFunc] = useState<(() => void) | null>(null);
  if (sampleFunc !== prevSampleFunc) {
    setPrevSampleFunc(() => sampleFunc);
  }

  return null;
}

The current behavior

You will see this error message:

  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

  1. added
    Status: Unconfirmed
    on Sep 4, 2026
  2. added a commit that references this issue on Oct 12, 2026
    2f5370a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Unconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions