Установить тип возврата для useClientRect
hook на [ClientRect | undefined, (node: HTMLDivElement) => void]
и изменить тип аргумента для useCallback
на HTMLDivElement
:
// packages
import { useCallback, useState } from "react";
function useClientRect(): [
ClientRect | undefined,
(node: HTMLDivElement) => void
] {
const [rect, setRect] = useState<ClientRect>();
const ref = useCallback((node: HTMLDivElement) => {
if (node !== null) {
setRect(node.getBoundingClientRect());
}
}, []);
return [rect, ref];
}
export default useClientRect;