-
-
Notifications
You must be signed in to change notification settings - Fork 2k
types: Require initial value in useRef
#4683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| export import CreateHandle = _hooks.CreateHandle; | ||
| export import EffectCallback = _hooks.EffectCallback; | ||
| export import Inputs = _hooks.Inputs; | ||
| export import PropRef = _hooks.PropRef; |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ofuseRefthat are really easy to stumble into. This is a breaking type change so v11 it goes.