Skip to content
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

[react] Require initial value for useRef #64920

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

eps1lon
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants