Skip to content

[react] Require initial value for useRef#64920

Closed
eps1lon wants to merge 16 commits intoDefinitelyTyped:masterfrom
eps1lon:feat/react/useRef-required
Closed

[react] Require initial value for useRef#64920
eps1lon wants to merge 16 commits intoDefinitelyTyped:masterfrom
eps1lon:feat/react/useRef-required

Conversation

@eps1lon
Copy link
Copy Markdown
Collaborator

@eps1lon eps1lon commented Mar 28, 2023

Implements https://twitter.com/dan_abramov/status/1640157848167489541
Stacked on #64896 (Diff against #64896)

useRef now requires an explicit initial value. This is in line with documentation and createContext

-const ref = React.useRef<T>()
+const ref = React.useRef<T>(undefined)
 //     ^? React.RefObject<T | undefined>

Just like for const current: T | null = useRef<T>(null).current we'll have a convenience overload for useRef<T>(undefined) that ensures ref.current will be T | undefined.

@eps1lon eps1lon force-pushed the feat/react/useRef-required branch from f8d98e5 to 40d0aa6 Compare December 5, 2023 21:15
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