# TypeError: Cannot read properties of null (reading 'focus') when using ref callback

- **ID:** `react/ref-callback-null-on-unmount`
- **Domain:** react
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A ref callback receives null when the component unmounts, and code attempts to access properties or methods on the ref without checking for null.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| React 18.2.0 | active | — | — |
| React 17.0.2 | active | — | — |

## Workarounds

1. **Add a null check before accessing properties on the ref. Use optional chaining or a guard clause.** (95% success)
   ```
   Add a null check before accessing properties on the ref. Use optional chaining or a guard clause.
   ```
2. **Use a ref callback with cleanup to handle the null case gracefully, especially when using third-party libraries.** (90% success)
   ```
   Use a ref callback with cleanup to handle the null case gracefully, especially when using third-party libraries.
   ```

## Dead Ends

- **** — useRef still holds a reference to the DOM node but can become stale; accessing .current after unmount may still be null or cause memory leaks. (50% fail)
- **** — setTimeout doesn't guarantee the component is still mounted; if unmount occurs during the delay, ref.current is null. (80% fail)
