Skip to content

feat: add support for null values to support react 19 internal type c… #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useEffect,
useState,
RefObject,
MutableRefObject,
useRef,
DependencyList,
} from 'react';
Expand Down Expand Up @@ -157,22 +156,22 @@ export const useDimensions = (options: IOptions = {}): Dimensions => {
return dimensions;
};

export function useRectEffect<T extends HTMLElement>(
export function useRectEffect<T extends HTMLElement | null>(
effect: (rect: Rect | null) => void,
ref: RefObject<T> | MutableRefObject<T>,
ref: RefObject<T>,
deps?: DependencyList,
): void;

export function useRectEffect<T extends HTMLElement>(
export function useRectEffect<T extends HTMLElement | null>(
effect: (rect: Rect | null) => void,
ref: RefObject<T> | MutableRefObject<T>,
ref: RefObject<T>,
options: FullOptions,
deps?: DependencyList,
): void;

export function useRectEffect<T extends HTMLElement>(
export function useRectEffect<T extends HTMLElement | null>(
effect: (rect: Rect | null) => void,
ref: RefObject<T> | MutableRefObject<T>,
ref: RefObject<T>,
third?: any,
fourth?: any,
) {
Expand All @@ -182,25 +181,25 @@ export function useRectEffect<T extends HTMLElement>(
{
...options,
recalculateLayoutBeforeUpdate: () =>
ref.current ? ref.current.getBoundingClientRect() : null,
ref?.current ? ref.current.getBoundingClientRect() : null,
},
[ref.current, ...deps],
[ref?.current, ...deps],
);
}

export function useRect<T extends HTMLElement>(
ref: RefObject<T> | MutableRefObject<T>,
export function useRect<T extends HTMLElement | null>(
ref: RefObject<T>,
deps?: DependencyList,
): Rect | null;

export function useRect<T extends HTMLElement>(
ref: RefObject<T> | MutableRefObject<T>,
export function useRect<T extends HTMLElement | null>(
ref: RefObject<T>,
options: FullOptions,
deps?: DependencyList,
): Rect | null;

export function useRect<T extends HTMLElement>(
ref: RefObject<T> | MutableRefObject<T>,
export function useRect<T extends HTMLElement | null>(
ref: RefObject<T>,
second: any,
third?: any,
): Rect | null {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-viewport-utils",
"version": "2.0.2",
"version": "2.0.3",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please never update the version in the commit. This happens automatically when a new version is created.

"description": "Utility components for working with the viewport in react",
"main": "dist/commonjs.js",
"module": "dist/esmodule.js",
Expand Down