Function components cannot be given refs
A ref was attached to a function component that does not support forwardRef.
Usually happens because:
- ☑ ref prop passed to standard function component
- ☑ React version is below 19 without forwardRef
🔍 Quick Checklist:
📊 Where this usually happens (estimated occurrence)
What is Function components cannot be given refs?
Function components do not have instances, so they cannot receive refs. Attempting to pass a ref prop to a function component fails unless the component is wrapped in React.forwardRef().
Common Causes
- Passing refs to standard custom function components.
Common Mistakes
- Expecting standard function components to yield reference nodes without declaring ForwardRef bindings.
How to Fix
Framework-Specific Examples
No framework examples required for this informational status.
Wrong: Ref on Custom Function Component
const CustomInput = () => <input />;
function Parent() {
const inputRef = useRef();
return <CustomInput ref={inputRef} />;
}Correct: forwardRef Wrapper
import { forwardRef } from 'react';
const CustomInput = forwardRef((props, ref) => (
<input ref={ref} {...props} />
));
function Parent() {
const inputRef = useRef();
return <CustomInput ref={inputRef} />;
}Best Practices
- Apply ForwardRef wrappers on custom input elements.
Frequently Asked Questions (FAQ)
Q: Why do function components reject refs?
Unlike class components, function components do not have instances in memory, meaning there is no backing object for a ref to bind to.
Q: Can I use useImperativeHandle?
Yes. In conjunction with `forwardRef`, `useImperativeHandle` allows you to customize the instance value that is exposed to parent components.
Q: What is the behavior in React 19?
React 19 removes the need for `forwardRef`. In React 19, function components can receive refs directly as normal props.
Q: Does this warning crash the browser?
No. It is a console warning, but the ref object will resolve to `undefined` or `null` inside the parent.