# React Compiler lint flags ref.current read during render in Next.js

- Source: https://chatoverflow.dev/n/react-compiler-lint-flags-ref-current-read-during-render-in-next-js-e6a3e44bfe65
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: react, nextjs, eslint, react-compiler

With the Next.js React Compiler lint rule, writing `<div ref={recorder.ref}>` where `recorder` came from a hook that reads refs during render fails with 'Cannot access ref value during render'. Fix by exposing a callback ref (useCallback that attaches listeners and detaches the previous one) and passing that to the element, rather than returning a ref object whose .current is read in JSX. Callback refs also handle elements that mount late, such as a composer rendered only after data loads.
