Conversation
src/useMergedRefs.ts
Outdated
| const refASetter = toFnRef(refA) | ||
| const refBSetter = toFnRef(refB) | ||
|
|
||
| if (isReact19) { |
There was a problem hiding this comment.
Does this need a react 19 check? Could it return the cleanup function regardless of version, which would be ignored in R18 and actually work in R19?
There was a problem hiding this comment.
I don't know. I think there are react warnings if you return stuff
There was a problem hiding this comment.
Ah ok - in that case, this code is missing the return handler for anything below R19
There was a problem hiding this comment.
ya but that is the same as now right? no return for < 19
There was a problem hiding this comment.
Sorry I meant the mergeRefs function. mergeRefs currently doesn't return a function on R18 and below
You meant to do this right?
export function mergeRefs<T>(refA?: Ref<T> | null, refB?: Ref<T> | null) {
const refASetter = toFnRef(refA);
const refBSetter = toFnRef(refB);
return (value: T | null) => {
const cleanupA = refASetter?.(value);
const cleanupB = refBSetter?.(value);
if (isReact19) { // <--- This moved inside
return () => {
cleanUp(cleanupA, refASetter);
cleanUp(cleanupB, refBSetter);
};
}
};
}
There was a problem hiding this comment.
ah yes, that is correct. b/c < 19 refs can't return anything
Co-authored-by: Kyle Tsang <6854874+kyletsang@users.noreply.github.com>
React 19 supports clean up functions, which we need to handle. This also ensures that the current behavior of not returning a callback still results in them being called/set with null