# ref as a Prop

> The `ref` as a prop in React allows function components to receive refs directly, without `forwardRef()`.

## Do I still need forwardRef in React?

The ability of function components to accept `ref` as a regular prop and pass it to a DOM element or another component. Makes `forwardRef()` unnecessary in new code.

- Topic: Basics
- Type: concept

## Example

Wrong:

```jsx
const Input = forwardRef(function Input(props, ref) {
  return <input ref={ref} {...props} />;
});
```

Right:

```jsx
function Input({ ref, ...props }) {
  return <input ref={ref} {...props} />;
}
```

Function components get `ref` as a normal prop, so the `forwardRef()` wrapper is no longer needed.

## Common mistakes

- AI-generated code still wraps every input component in `forwardRef()` out of habit.

## Key points

- Function components read `ref` from props, without wrapping them in `forwardRef()`.
- In TypeScript, the props type includes `ref`, e.g. `ref?: React.Ref<HTMLInputElement>`.
- Ref callbacks that set something up return a cleanup function.

## Interview questions

### Is forwardRef deprecated?

It still works, but function components no longer need it, and React plans to deprecate it.

### Does ref as a prop work for class components?

No. For class components, `ref` still points to the class instance and is not passed in props.

## Related cards

- [forwardRef()](https://wonderium.dev/react/forward-ref.md)
- [useRef()](https://wonderium.dev/react/use-ref.md)
- [References](https://wonderium.dev/react/references.md)
- [useImperativeHandle()](https://wonderium.dev/react/use-imperative-handle.md)
- [Props Drilling](https://wonderium.dev/react/props-drilling.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/ref-as-prop
- Last updated: 2026-11-25
