Skip to content

Conversation

@rschristian
Copy link
Member

I quite like the change React made to their types in v19 to require an initial argument be passed to useRef, it fixes some of the fiddly details of useRef that are really easy to stumble into. This is a breaking type change so v11 it goes.

export import CreateHandle = _hooks.CreateHandle;
export import EffectCallback = _hooks.EffectCallback;
export import Inputs = _hooks.Inputs;
export import PropRef = _hooks.PropRef;
Copy link
Member Author

Choose a reason for hiding this comment

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

This has never existed in React's types, not quite sure what it was supposed to be either.

export type Key = string | number | any;

export type RefObject<T> = { current: T | null };
export type RefObject<T> = { current: T };
Copy link
Member Author

Choose a reason for hiding this comment

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

React for reference. Setting .current to T is much better, IMO.

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;
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +64 to +66
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>;
Copy link
Member Author

Choose a reason for hiding this comment

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

@rschristian rschristian merged commit 8811459 into v11-2 Feb 18, 2025
7 checks passed
@rschristian rschristian deleted the types/use-ref-initial branch February 18, 2025 06:14
JoviDeCroock pushed a commit that referenced this pull request Feb 18, 2025
JoviDeCroock pushed a commit that referenced this pull request Feb 19, 2025
JoviDeCroock pushed a commit that referenced this pull request Feb 19, 2025
JoviDeCroock pushed a commit that referenced this pull request Feb 19, 2025
JoviDeCroock pushed a commit that referenced this pull request Feb 26, 2025
JoviDeCroock pushed a commit that referenced this pull request Feb 27, 2025
JoviDeCroock pushed a commit that referenced this pull request Mar 1, 2025
JoviDeCroock pushed a commit that referenced this pull request Mar 9, 2025
JoviDeCroock pushed a commit that referenced this pull request Mar 14, 2025
JoviDeCroock pushed a commit that referenced this pull request Mar 22, 2025
JoviDeCroock pushed a commit that referenced this pull request Apr 8, 2025
JoviDeCroock pushed a commit that referenced this pull request May 3, 2025
JoviDeCroock pushed a commit that referenced this pull request May 8, 2025
JoviDeCroock pushed a commit that referenced this pull request May 23, 2025
JoviDeCroock pushed a commit that referenced this pull request May 30, 2025
JoviDeCroock pushed a commit that referenced this pull request Jun 6, 2025
@JoviDeCroock JoviDeCroock mentioned this pull request Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants