DocumentationRulesno-string-refs

no-string-refs

Rule category

Restriction.

What it does

Disallows using deprecated string refs.

Why is this bad?

String refs are deprecated in React. Use callback refs instead.

Examples

Failing

import React from "react";
 
function Example() {
  return <div ref="ref" />;
  //              ^^^^^
  //              - [Deprecated] Use callback refs instead.
}

Passing

import React, { useRef } from "react";
 
function Example() {
  const ref = useRef<HTMLDivElement>(null);
  return <div ref={ref} />;
}