Documentation
Rules
no-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" />;
  //              ^^^^^
  //              - String refs are deprecated. Use callback refs instead.
}

Passing

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