From eca3229fbd26306b877e8da297569ec4a9448d5e Mon Sep 17 00:00:00 2001 From: Lukas Germerott Date: Mon, 12 May 2025 13:07:10 +0200 Subject: [PATCH] feat: add support for null values to support react 19 internal type changes --- lib/hooks.ts | 29 ++++++++++++++--------------- package.json | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/hooks.ts b/lib/hooks.ts index de8d92f..ca77c22 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -3,7 +3,6 @@ import { useEffect, useState, RefObject, - MutableRefObject, useRef, DependencyList, } from 'react'; @@ -157,22 +156,22 @@ export const useDimensions = (options: IOptions = {}): Dimensions => { return dimensions; }; -export function useRectEffect( +export function useRectEffect( effect: (rect: Rect | null) => void, - ref: RefObject | MutableRefObject, + ref: RefObject, deps?: DependencyList, ): void; -export function useRectEffect( +export function useRectEffect( effect: (rect: Rect | null) => void, - ref: RefObject | MutableRefObject, + ref: RefObject, options: FullOptions, deps?: DependencyList, ): void; -export function useRectEffect( +export function useRectEffect( effect: (rect: Rect | null) => void, - ref: RefObject | MutableRefObject, + ref: RefObject, third?: any, fourth?: any, ) { @@ -182,25 +181,25 @@ export function useRectEffect( { ...options, recalculateLayoutBeforeUpdate: () => - ref.current ? ref.current.getBoundingClientRect() : null, + ref?.current ? ref.current.getBoundingClientRect() : null, }, - [ref.current, ...deps], + [ref?.current, ...deps], ); } -export function useRect( - ref: RefObject | MutableRefObject, +export function useRect( + ref: RefObject, deps?: DependencyList, ): Rect | null; -export function useRect( - ref: RefObject | MutableRefObject, +export function useRect( + ref: RefObject, options: FullOptions, deps?: DependencyList, ): Rect | null; -export function useRect( - ref: RefObject | MutableRefObject, +export function useRect( + ref: RefObject, second: any, third?: any, ): Rect | null { diff --git a/package.json b/package.json index ad2efd2..cd80b70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-viewport-utils", - "version": "2.0.2", + "version": "2.0.3", "description": "Utility components for working with the viewport in react", "main": "dist/commonjs.js", "module": "dist/esmodule.js",