Created
August 31, 2023 09:50
-
-
Save moeriki/7d5f694c917a26e8cc4de1f7f218286e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function useInnerRef<T>(forwardedRef: ForwardedRef<T>) { | |
const innerRef = useRef<T | null>(null); | |
const setInnerRef: RefCallback<T> = (element: T | null) => { | |
if (typeof forwardedRef === 'function') { | |
forwardedRef(element); | |
} else if (forwardedRef) { | |
forwardedRef.current = element; | |
} | |
innerRef.current = element; | |
}; | |
return [innerRef, setInnerRef] as const; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment