Skip to content
Merged
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 src/misc/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DebouncedFunction<T extends (this: any, ...args: any[]) => any>
* Simplest implementation of "debounce" function.
* Returns function wrapper that delays original function call
* until timeout since last call will be reached.
* Analogue of debounce from lodash/underscore.
* Similar to `debounce` from lodash/underscore.
*
* @param func Function.
* @param timeout Timeout in milliseconds.
Expand Down
4 changes: 2 additions & 2 deletions src/react/error-boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, type ErrorInfo, type JSX, type ReactNode } from 'react';
import { Component, type ErrorInfo, type ReactNode } from 'react';

export interface ErrorBoundaryProps {
children?: ReactNode;
Expand Down Expand Up @@ -34,7 +34,7 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
}

/** @inheritdoc */
override render(): JSX.Element {
override render(): ReactNode {
const { children, fallback } = this.props;

return <>{this.state.hasError ? fallback : children}</>;
Expand Down
4 changes: 2 additions & 2 deletions src/react/lifecycle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type JSX, type ReactNode, useEffect } from 'react';
import { type ReactNode, useEffect } from 'react';
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.ts';
import { useLatestRef } from './use-latest-ref.ts';

Expand All @@ -25,7 +25,7 @@ export interface LifecycleProps {
* @param props Props.
* @returns JSX Element.
*/
export function Lifecycle(props: LifecycleProps): JSX.Element {
export function Lifecycle(props: LifecycleProps): ReactNode {
const { children } = props;

// because it is "event callbacks", we should call actual functions (from last render),
Expand Down
4 changes: 2 additions & 2 deletions src/react/merge-refs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Ref, RefObject, RefCallback, MutableRefObject } from 'react';
import type { Ref, RefObject, RefCallback } from 'react';

/**
* Create ref that updates all accepted refs from list.
Expand All @@ -7,7 +7,7 @@ import type { Ref, RefObject, RefCallback, MutableRefObject } from 'react';
* @returns Merged ref.
*/
export function mergeRefs<T>(
list: Array<Ref<T> | RefObject<T> | RefCallback<T> | MutableRefObject<T> | null | undefined>,
list: Array<Ref<T> | RefObject<T> | RefCallback<T> | null | undefined>,
): Ref<T> {
return (value: T) => {
for (const ref of list) {
Expand Down
4 changes: 2 additions & 2 deletions src/react/portal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type JSX, type ReactNode, useState } from 'react';
import { type ReactNode, useState } from 'react';
import { createPortal } from 'react-dom';
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.ts';
import { useLatestRef } from './use-latest-ref.ts';
Expand Down Expand Up @@ -60,7 +60,7 @@ const DEFAULTS = {
* @param props Props.
* @returns JSX.Element or null.
*/
export function Portal(props: PortalProps): JSX.Element | null {
export function Portal(props: PortalProps): ReactNode {
const { children, portalKey } = props;

const [container, setContainer] = useState<HTMLElement | null>(null);
Expand Down
10 changes: 2 additions & 8 deletions src/react/use-drag-and-drop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RefObject, type DependencyList, type MutableRefObject, useMemo } from 'react';
import { type RefObject, type DependencyList, useMemo } from 'react';
import { type Point2d, Vector2 } from '../math/mod.ts';
import { getPositionedParentOffset } from '../dom/mod.ts';
import { useIsomorphicLayoutEffect } from '../react/use-isomorphic-layout-effect.ts';
Expand Down Expand Up @@ -77,13 +77,7 @@ function canStartDragDefault(event: TouchEvent | PointerEvent | MouseEvent): boo
* @param options Options.
*/
export function useDragAndDrop<T extends HTMLElement>(
ref:
| RefObject<T>
| RefObject<T | null>
| RefObject<T | undefined>
| MutableRefObject<T>
| MutableRefObject<T | null>
| MutableRefObject<T | undefined>,
ref: RefObject<T> | RefObject<T | null> | RefObject<T | undefined>,
{
strategy = 'absolute',
disabled,
Expand Down
17 changes: 2 additions & 15 deletions src/react/use-intersection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
type RefObject,
type MutableRefObject,
useContext,
useMemo,
useRef,
type DependencyList,
} from 'react';
import { type RefObject, useContext, useMemo, useRef, type DependencyList } from 'react';
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.ts';
import { useLatestRef } from './use-latest-ref.ts';
import { IntersectionObserverContext } from './context/intersection-observer-context.ts';
Expand All @@ -24,13 +17,7 @@ export interface UseIntersectionOptions extends IntersectionObserverInit {
* @param options Observe options.
*/
export function useIntersection<T extends Element>(
ref:
| RefObject<T>
| RefObject<T | null>
| RefObject<T | undefined>
| MutableRefObject<T>
| MutableRefObject<T | null>
| MutableRefObject<T | undefined>,
ref: RefObject<T> | RefObject<T | null> | RefObject<T | undefined>,
callback: (entry: IntersectionObserverEntry) => void,
{ extraDeps = zeroDeps, ...options }: UseIntersectionOptions = {},
): void {
Expand Down
4 changes: 2 additions & 2 deletions src/react/use-latest-ref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MutableRefObject, useRef } from 'react';
import { type RefObject, useRef } from 'react';

/**
* Returns ref that automatically actualizes current value each render.
Expand All @@ -10,7 +10,7 @@ import { type MutableRefObject, useRef } from 'react';
* @param value Current value.
* @returns Ref object.
*/
export function useLatestRef<T>(value: T): MutableRefObject<T> {
export function useLatestRef<T>(value: T): RefObject<T> {
const ref = useRef<T>(value);

// immediately update value if it is not equals to current
Expand Down
6 changes: 3 additions & 3 deletions src/react/use-merge-refs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type Ref, type RefCallback, type RefObject, type MutableRefObject, useRef } from 'react';
import { type Ref, type RefCallback, type RefObject, useRef } from 'react';
import { mergeRefs } from './merge-refs.ts';

interface HookState<T> {
refs: Array<Ref<T> | RefObject<T> | RefCallback<T> | MutableRefObject<T> | null | undefined>;
refs: Array<Ref<T> | RefObject<T> | RefCallback<T> | null | undefined>;
merged: Ref<T>;
}

Expand All @@ -12,7 +12,7 @@ interface HookState<T> {
* @returns Merged ref.
*/
export function useMergeRefs<T>(
refs: Array<Ref<T> | RefObject<T> | RefCallback<T> | MutableRefObject<T> | null | undefined>,
refs: Array<Ref<T> | RefObject<T> | RefCallback<T> | null | undefined>,
): Ref<T> {
const stateRef = useRef<HookState<T>>(null);

Expand Down
16 changes: 2 additions & 14 deletions src/react/use-resize.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
type RefObject,
type MutableRefObject,
useContext,
useMemo,
type DependencyList,
} from 'react';
import { type RefObject, useContext, useMemo, type DependencyList } from 'react';
import { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.ts';
import { useLatestRef } from './use-latest-ref.ts';
import { ResizeObserverContext } from './context/resize-observer-context.ts';
Expand All @@ -22,13 +16,7 @@ export interface UseResizeOptions extends ResizeObserverOptions {
* @param options Resize observer options.
*/
export function useResize<T extends Element>(
ref:
| RefObject<T>
| RefObject<T | null>
| RefObject<T | undefined>
| MutableRefObject<T>
| MutableRefObject<T | null>
| MutableRefObject<T | undefined>,
ref: RefObject<T> | RefObject<T | null> | RefObject<T | undefined>,
callback: (entry: ResizeObserverEntry) => void,
{ extraDeps = zeroDeps, ...options }: UseResizeOptions = {},
): void {
Expand Down