Skip to content

Commit

Permalink
types: Require initial value in useRef (#4683)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored and JoviDeCroock committed Feb 19, 2025
1 parent d9a6c58 commit d67c5b4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ declare namespace React {
export import CreateHandle = _hooks.CreateHandle;
export import EffectCallback = _hooks.EffectCallback;
export import Inputs = _hooks.Inputs;
export import PropRef = _hooks.PropRef;
export import Reducer = _hooks.Reducer;
export import Dispatch = _hooks.Dispatch;
export import SetStateAction = _hooks.StateUpdater;
Expand Down
13 changes: 3 additions & 10 deletions hooks/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ export function useReducer<S, A, I>(
init: (arg: I) => S
): [S, Dispatch<A>];

/** @deprecated Use the `Ref` type instead. */
type PropRef<T> = MutableRef<T>;

interface MutableRef<T> {
current: T;
}

/**
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
* (`initialValue`). The returned object will persist for the full lifetime of the component.
Expand All @@ -68,9 +61,9 @@ interface MutableRef<T> {
*
* @param initialValue the initial value to store in the ref object
*/
export function useRef<T>(initialValue: T): MutableRef<T>;
export function useRef<T>(initialValue: T | null): RefObject<T>;
export function useRef<T = undefined>(): MutableRef<T | undefined>;
export function useRef<T>(initialValue: T): RefObject<T>;
export function useRef<T>(initialValue: T | null): RefObject<T | null>;
export function useRef<T>(initialValue: T | undefined): RefObject<T | undefined>;

type EffectCallback = () => void | (() => void);
/**
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export interface VNode<P = {}> {

export type Key = string | number | any;

export type RefObject<T> = { current: T | null };
export type RefObject<T> = { current: T };
export type RefCallback<T> = (instance: T | null) => void;
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;

export type ComponentChild =
| VNode<any>
Expand Down

0 comments on commit d67c5b4

Please sign in to comment.