# refs

Rule `react-hooks/refs`. Validates correct usage of refs, not reading/writing during render. See the "pitfalls" section in `useRef()` usage

- Source: react-hooks
- Technologies: React
- Kind: correctness
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 165.2M weekly downloads of presets that enable it
- Trend: +28.2% last quarter
- Rank: #100 by reach, #1349 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `react-hooks/refs` | yes | safe | package `eslint-plugin-react-hooks` | [docs](https://react.dev/reference/eslint-plugin-react-hooks/lints/refs) |
| Oxlint | `react/refs` | no | no | plugin `react`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/react/refs.html) |

## Code examples

### Incorrect: the rule reports this

```js
function Component() {
  const ref = useRef(0);
  const value = ref.current; // Don't read during render
  return <div>{value}</div>;
}
```

```js
function Component({value}) {
  const ref = useRef(null);
  ref.current = value; // Don't modify during render
  return <div />;
}
```

### Correct: the rule accepts this

```js
function Component() {
  const ref = useRef(null);

  useEffect(() => {
    if (ref.current) {
      console.log(ref.current.offsetWidth); // OK in effect
    }
  });

  return <div ref={ref} />;
}
```

```js
function Component() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      {count}
    </button>
  );
}
```

```js
function Component() {
  const ref = useRef(null);

  // Initialize only once on first use
  if (ref.current === null) {
    ref.current = expensiveComputation(); // OK - lazy initialization
  }

  const handleClick = () => {
    console.log(ref.current); // Use the initialized value
  };

  return <button onClick={handleClick}>Click</button>;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import reactHooks from "eslint-plugin-react-hooks";

export default [
  {
    plugins: { "react-hooks": reactHooks },
    rules: {
      "react-hooks/refs": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "react"
  ],
  "rules": {
    "react/refs": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [React Hooks recommended](https://lintradar.dev/presets/react-hooks-recommended.md) | ESLint | `eslint-plugin-react-hooks` | 16 | 118.4M | +21.5% |
| [Next.js Core Web Vitals](https://lintradar.dev/presets/next-core-web-vitals.md) | ESLint | `eslint-config-next` | 62 | 46.8M | +48.8% |

## Related rules

- [react-hooks/purity](https://lintradar.dev/rules/react-hooks/purity.md): Validates that components/hooks are pure by checking that they do not call known-impure functions
- [react-hooks/set-state-in-effect](https://lintradar.dev/rules/react-hooks/set-state-in-effect.md): Validates against calling setState synchronously in an effect. This can indicate non-local derived data, a derived event pattern, or improper external data synchronization.
- [react-hooks/preserve-manual-memoization](https://lintradar.dev/rules/react-hooks/preserve-manual-memoization.md): Validates that existing manual memoized is preserved by the compiler. React Compiler will only compile components and hooks if its inference matches or exceeds the existing manual memoization
- [react-hooks/set-state-in-render](https://lintradar.dev/rules/react-hooks/set-state-in-render.md): Validates against setting state during render, which can trigger additional renders and potential infinite render loops
- [react-hooks/incompatible-library](https://lintradar.dev/rules/react-hooks/incompatible-library.md): Validates against usage of libraries which are incompatible with memoization (manual or automatic)
- [react-hooks/static-components](https://lintradar.dev/rules/react-hooks/static-components.md): Validates that components are static, not recreated every render. Components that are recreated dynamically can reset state and trigger excessive re-rendering

---

Web page: https://lintradar.dev/rules/react-hooks/refs. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
