refs on function components React Origin: On your device Last updated 14 Oct 2026

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

A ref was passed to a function component that doesn’t forward it.

Exact message you may see Function components cannot be given refsDid you mean to use React.forwardRef()
Seen on: React

Meaning

Before React 19, function components need forwardRef to receive refs. Libraries (form libs, animation libs, tooltips) pass refs to your custom components.

Common causes

  • Custom input/button components used with refs
  • Library wrapping your component and attaching a ref

⚡ Quick fix

  1. Wrap with React.forwardRef and pass the ref to a DOM element
  2. React 19: accept ref as a normal prop

Detailed fix by platform

React

  1. const Input = forwardRef((props, ref) => <input ref={ref} {...props} />);

How to diagnose

  1. Component — Which one receives the ref?
  2. Version — React 18 or 19?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Adjacent JSX elements — Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (React)Adjacent JSX elementsbroken ref — warning: ignoring broken ref refs/remotes/origin/HEAD (Git)broken refcannot lock ref — error: cannot lock ref 'refs/remotes/origin/x': is at … but expected … / unable to update local ref (Git)cannot lock refcomponentWillMount renamed — Warning: componentWillMount has been renamed, and is not recommended for use. (React)componentWillMount re…Failed to resolve component — Vue: [Vue warn]: Failed to resolve component: x (Vue)Failed to resolve com…not wrapped in act — Warning: An update to Component inside a test was not wrapped in act(...) (React)not wrapped in actsetState during render — Warning: Cannot update a component (`Parent`) while rendering a different component (`Child`) (React)setState during renderuncontrolled to controlled — Warning: A component is changing an uncontrolled input to be controlled (React)uncontrolled to contr…refs on f…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.