Skip to content

noReactStringRefs

biome.json
{
"linter": {
"rules": {
"nursery": {
"noReactStringRefs": "error"
}
}
}
}

Disallow string refs in React components.

String refs are a legacy React feature. Modern React code should use callback refs, createRef(), or useRef() instead.

Biome also flags template literal refs, even though upstream only does so through an option.

function Hello() {
return <div ref="hello">Hello</div>;
}
code-block.jsx:2:19 lint/nursery/noReactStringRefs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

String refs are deprecated.

1 │ function Hello() {
> 2 │ return <div ref=“hello”>Hello</div>;
^^^^^^^
3 │ }
4 │

String refs are a legacy React feature that can make ref usage harder to follow.

Use a callback ref or an object ref created with createRef() or useRef() instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

function Hello({ id }) {
return <div ref={`hello-${id}`}>Hello</div>;
}
code-block.jsx:2:19 lint/nursery/noReactStringRefs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

String refs are deprecated.

1 │ function Hello({ id }) {
> 2 │ return <div ref={`hello-${id}`}>Hello</div>;
^^^^^^^^^^^^^^^
3 │ }
4 │

String refs are a legacy React feature that can make ref usage harder to follow.

Use a callback ref or an object ref created with createRef() or useRef() instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

class Hello extends React.Component {
componentDidMount() {
this.refs.hello.focus();
}
}
code-block.jsx:3:5 lint/nursery/noReactStringRefs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Using this.refs is deprecated.

1 │ class Hello extends React.Component {
2 │ componentDidMount() {
> 3 │ this.refs.hello.focus();
^^^^^^^^^
4 │ }
5 │ }

Accessing refs through this.refs relies on React’s legacy string ref behavior.

Store the ref on an instance field with a callback ref, or switch to createRef() or useRef().

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

function Hello() {
const helloRef = useRef(null);
return <div ref={helloRef}>Hello</div>;
}