Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 1.17 KB

forward-ref-uses-ref.md

File metadata and controls

45 lines (29 loc) · 1.17 KB

Require all forwardRef components include a ref parameter (react/forward-ref-uses-ref)

💡 This rule is manually fixable by editor suggestions.

Requires that components wrapped with forwardRef must have a ref parameter. Omitting the ref argument is usually a bug, and components not using ref don't need to be wrapped by forwardRef.

See https://react.dev/reference/react/forwardRef

Rule Details

This rule checks all React components using forwardRef and verifies that there is a second parameter.

The following patterns are considered warnings:

var React = require('react');

var Component = React.forwardRef((props) => (
    <div />
));

The following patterns are not considered warnings:

var React = require('react');

var Component = React.forwardRef((props, ref) => (
    <div ref={ref} />
));

var Component = React.forwardRef((props, ref) => (
    <div />
));

function Component(props) {
    return <div />;
};

When not to use

If you don't want to enforce that components using forwardRef utilize the forwarded ref.