-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Provide a general summary of the issue here
See https://react.dev/blog/2024/12/05/react-19#cleanup-functions-for-refs
and:
react-spectrum/packages/@react-aria/utils/src/useObjectRef.ts
Lines 24 to 38 in cfe79d3
| export function useObjectRef<T>(forwardedRef?: ((instance: T | null) => void) | MutableRefObject<T | null> | null): MutableRefObject<T | null> { | |
| const objRef: MutableRefObject<T | null> = useRef<T>(null); | |
| return useMemo(() => ({ | |
| get current() { | |
| return objRef.current; | |
| }, | |
| set current(value) { | |
| objRef.current = value; | |
| if (typeof forwardedRef === 'function') { | |
| forwardedRef(value); | |
| } else if (forwardedRef) { | |
| forwardedRef.current = value; | |
| } | |
| } | |
| }), [forwardedRef]); |
🤔 Expected Behavior?
if a ref is provided to a component and I return a function for cleanup from it, it is called on cleanup.
😯 Current Behavior
the cleanup function is not respected.
💁 Possible Solution
Keep a reference to the cleanup function and call it as required - keeping the react 19 behavior of not calling with null if a callback is returned.
I will be happy to make a PR.
🔦 Context
we are doing complex handling in ref callbacks around the table and we can't use this new react 19 functionality.
Note also that it will in future become the default and they will stop sending null.
🖥️ Steps to Reproduce
use a ref on a component using useObjectRef
Version
3.38.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
Windows
🧢 Your Company/Team
Saxo Bank
🕷 Tracking Issue
No response