Skip to content

Commit ef1f51f

Browse files
rschristianJoviDeCroock
authored andcommitted
types: Require initial value in useRef (#4683)
1 parent b0ffc7f commit ef1f51f

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

compat/src/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ declare namespace React {
117117
export import CreateHandle = _hooks.CreateHandle;
118118
export import EffectCallback = _hooks.EffectCallback;
119119
export import Inputs = _hooks.Inputs;
120-
export import PropRef = _hooks.PropRef;
121120
export import Reducer = _hooks.Reducer;
122121
export import Dispatch = _hooks.Dispatch;
123122
export import SetStateAction = _hooks.StateUpdater;

hooks/src/index.d.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ export function useReducer<S, A, I>(
5252
init: (arg: I) => S
5353
): [S, Dispatch<A>];
5454

55-
/** @deprecated Use the `Ref` type instead. */
56-
type PropRef<T> = MutableRef<T>;
57-
58-
interface MutableRef<T> {
59-
current: T;
60-
}
61-
6255
/**
6356
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
6457
* (`initialValue`). The returned object will persist for the full lifetime of the component.
@@ -68,9 +61,9 @@ interface MutableRef<T> {
6861
*
6962
* @param initialValue the initial value to store in the ref object
7063
*/
71-
export function useRef<T>(initialValue: T): MutableRef<T>;
72-
export function useRef<T>(initialValue: T | null): RefObject<T>;
73-
export function useRef<T = undefined>(): MutableRef<T | undefined>;
64+
export function useRef<T>(initialValue: T): RefObject<T>;
65+
export function useRef<T>(initialValue: T | null): RefObject<T | null>;
66+
export function useRef<T>(initialValue: T | undefined): RefObject<T | undefined>;
7467

7568
type EffectCallback = () => void | (() => void);
7669
/**

src/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export interface VNode<P = {}> {
3737

3838
export type Key = string | number | any;
3939

40-
export type RefObject<T> = { current: T | null };
40+
export type RefObject<T> = { current: T };
4141
export type RefCallback<T> = (instance: T | null) => void;
42-
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
42+
export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;
4343

4444
export type ComponentChild =
4545
| VNode<any>

0 commit comments

Comments
 (0)