Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion docs/useEnsuredForwardedRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ const Child = React.forwardRef((props, ref) => {
```ts
ensuredForwardRef<T, P = {}>(Component: RefForwardingComponent<T, P>): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;

useEnsuredForwardedRef<T>(ref: React.MutableRefObject<T>): React.MutableRefObject<T>;
useEnsuredForwardedRef<T>(ref: React.MutableRefObject<T | null>): React.MutableRefObject<T | null>;
```
2 changes: 1 addition & 1 deletion docs/useIntersection.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Demo = () => {

```ts
useIntersection(
ref: RefObject<HTMLElement>,
ref: RefObject<HTMLElement | null>,
options: IntersectionObserverInit,
): IntersectionObserverEntry | null;
```
2 changes: 1 addition & 1 deletion docs/useLatest.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ const Demo = () => {
## Reference

```ts
const latestState = useLatest = <T>(state: T): MutableRefObject<T>;
const latestState = useLatest = <T>(state: T): MutableRefObject<T | null>;
```
2 changes: 1 addition & 1 deletion docs/useLockBodyScroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Demo = () => {
## Reference

```ts
useLockBodyScroll(locked: boolean = true, elementRef?: RefObject<HTMLElement>);
useLockBodyScroll(locked: boolean = true, elementRef?: RefObject<HTMLElement | null>);
```

- `locked` &mdash; Hook will lock scrolling on the body element if `true`, defaults to `true`
Expand Down
2 changes: 1 addition & 1 deletion docs/useScroll.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ const Demo = () => {
## Reference

```ts
useScroll(ref: RefObject<HTMLElement>);
useScroll(ref: RefObject<HTMLElement | null>);
```
2 changes: 1 addition & 1 deletion docs/useScrolling.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ const Demo = () => {
## Reference

```ts
useScrolling(ref: RefObject<HTMLElement>);
useScrolling(ref: RefObject<HTMLElement | null>);
```
2 changes: 1 addition & 1 deletion src/factory/createHTMLMediaHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
seek: (time: number) => void;
}

type MediaPropsWithRef<T> = HTMLMediaProps & { ref?: React.MutableRefObject<T | null> };
type MediaPropsWithRef<T> = HTMLMediaProps & { ref?: React.MutableRefObject<T | null | null> };

export default function createHTMLMediaHook<T extends HTMLAudioElement | HTMLVideoElement>(
tag: 'audio' | 'video'
Expand Down Expand Up @@ -235,7 +235,7 @@
if (props.autoPlay && el.paused) {
controls.play();
}
}, [props.src]);

Check warning on line 238 in src/factory/createHTMLMediaHook.ts

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'controls', 'props.autoPlay', and 'setState'. Either include them or remove the dependency array

return [element, state, controls, ref] as const;
};
Expand Down
6 changes: 3 additions & 3 deletions src/useEnsuredForwardedRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
} from 'react';

export default function useEnsuredForwardedRef<T>(
forwardedRef: MutableRefObject<T>
): MutableRefObject<T> {
forwardedRef: MutableRefObject<T | null>
): MutableRefObject<T | null> {
const ensuredRef = useRef(forwardedRef && forwardedRef.current);

useEffect(() => {
Expand All @@ -29,7 +29,7 @@ export function ensuredForwardRef<T, P = {}>(
Component: RefForwardingComponent<T, P>
): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>> {
return forwardRef((props: PropsWithChildren<P>, ref) => {
const ensuredRef = useEnsuredForwardedRef(ref as MutableRefObject<T>);
const ensuredRef = useEnsuredForwardedRef(ref as MutableRefObject<T | null>);
return Component(props, ensuredRef);
});
}
2 changes: 1 addition & 1 deletion src/useFullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface FullScreenOptions {
}

const useFullscreen = (
ref: RefObject<Element>,
ref: RefObject<Element | null>,
enabled: boolean,
options: FullScreenOptions = {}
): boolean => {
Expand Down
2 changes: 1 addition & 1 deletion src/useIntersection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RefObject, useEffect, useState } from 'react';

const useIntersection = (
ref: RefObject<HTMLElement>,
ref: RefObject<HTMLElement | null>,
options: IntersectionObserverInit
): IntersectionObserverEntry | null => {
const [intersectionObserverEntry, setIntersectionObserverEntry] =
Expand Down
7 changes: 5 additions & 2 deletions src/useLockBodyScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ const doc: Document | undefined = typeof document === 'object' ? document : unde
let documentListenerAdded = false;

export default !doc
? function useLockBodyMock(_locked: boolean = true, _elementRef?: RefObject<HTMLElement>) {}
: function useLockBody(locked: boolean = true, elementRef?: RefObject<HTMLElement>) {
? function useLockBodyMock(
_locked: boolean = true,
_elementRef?: RefObject<HTMLElement | null>
) {}
: function useLockBody(locked: boolean = true, elementRef?: RefObject<HTMLElement | null>) {
const bodyRef = useRef(doc!.body);
elementRef = elementRef || bodyRef;

Expand Down
2 changes: 1 addition & 1 deletion src/useMeasureDirty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ContentRect {
bottom: number;
}

const useMeasureDirty = (ref: RefObject<HTMLElement>): ContentRect => {
const useMeasureDirty = (ref: RefObject<HTMLElement | null>): ContentRect => {
const frame = useRef(0);
const [rect, set] = useState({
width: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/useMouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface State {
elW: number;
}

const useMouse = (ref: RefObject<Element>): State => {
const useMouse = (ref: RefObject<Element | null>): State => {
if (process.env.NODE_ENV === 'development') {
if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
console.error('useMouse expects a single ref argument.');
Expand Down
5 changes: 4 additions & 1 deletion src/useMouseHovered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export interface UseMouseHoveredOptions {

const nullRef = { current: null };

const useMouseHovered = (ref: RefObject<Element>, options: UseMouseHoveredOptions = {}): State => {
const useMouseHovered = (
ref: RefObject<Element | null>,
options: UseMouseHoveredOptions = {}
): State => {
const whenHovered = !!options.whenHovered;
const bound = !!options.bound;

Expand Down
2 changes: 1 addition & 1 deletion src/usePinchZoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum ZoomState {

export type ZoomStateType = ZoomState.ZOOMING_IN | ZoomState.ZOOMING_OUT;

const usePinchZoom = (ref: RefObject<HTMLElement>) => {
const usePinchZoom = (ref: RefObject<HTMLElement | null>) => {
const cacheRef = useMemo<CacheRef>(
() => ({
evCache: [],
Expand Down
2 changes: 1 addition & 1 deletion src/useScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface State {
y: number;
}

const useScroll = (ref: RefObject<HTMLElement>): State => {
const useScroll = (ref: RefObject<HTMLElement | null>): State => {
if (process.env.NODE_ENV === 'development') {
if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
console.error('`useScroll` expects a single ref argument.');
Expand Down
2 changes: 1 addition & 1 deletion src/useScrolling.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RefObject, useEffect, useState } from 'react';
import { off, on } from './misc/util';

const useScrolling = (ref: RefObject<HTMLElement>): boolean => {
const useScrolling = (ref: RefObject<HTMLElement | null>): boolean => {
const [scrolling, setScrolling] = useState<boolean>(false);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Options {
vertical?: boolean;
}

const useSlider = (ref: RefObject<HTMLElement>, options: Partial<Options> = {}): State => {
const useSlider = (ref: RefObject<HTMLElement | null>, options: Partial<Options> = {}): State => {
const isMounted = useMountedState();
const isSliding = useRef(false);
const valueRef = useRef(0);
Expand Down
2 changes: 1 addition & 1 deletion stories/useEnsuredForwardedRef.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Demo = ({ activeForwardRef }) => {
);
};

const Child = forwardRef(({}, ref: MutableRefObject<HTMLTextAreaElement>) => {
const Child = forwardRef(({}, ref: MutableRefObject<HTMLTextAreaElement | null>) => {
const ensuredForwardRef = useEnsuredForwardedRef(ref);

const [size, setSize] = useState(INITIAL_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion tests/useEnsuredForwardedRef.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('should return a valid ref when the forwarded ref is undefined', () => {

const { ensuredRef } = result.current;

expect(ensuredRef.current.id).toBe('test_id');
expect(ensuredRef.current?.id).toBe('test_id');
});

test('should return a valid ref when using the wrapper function style', () => {
Expand Down
Loading