-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
experimental_use(context) for server components and ssr #25226
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ import { | |
enableUseMemoCacheHook, | ||
} from 'shared/ReactFeatureFlags'; | ||
import is from 'shared/objectIs'; | ||
import { | ||
REACT_SERVER_CONTEXT_TYPE, | ||
REACT_CONTEXT_TYPE, | ||
} from 'shared/ReactSymbols'; | ||
|
||
type BasicStateAction<S> = (S => S) | S; | ||
type Dispatch<A> = A => void; | ||
|
@@ -616,8 +620,13 @@ function use<T>(usable: Usable<T>): T { | |
} | ||
} | ||
} | ||
} else { | ||
// TODO: Add support for Context | ||
} else if ( | ||
usable.$$typeof != null && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't notice this in the previous PR, but this null check isn't necessary, right? If it's undefined or null, the check below will fail anyway. |
||
(usable.$$typeof === REACT_CONTEXT_TYPE || | ||
usable.$$typeof === REACT_SERVER_CONTEXT_TYPE) | ||
) { | ||
const context: ReactContext<T> = (usable: any); | ||
return readContext(context); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,8 +200,12 @@ function use<T>(usable: Usable<T>): T { | |
} | ||
} | ||
} | ||
} else { | ||
// TODO: Add support for Context | ||
} else if ( | ||
usable.$$typeof != null && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
usable.$$typeof === REACT_SERVER_CONTEXT_TYPE | ||
) { | ||
const context: ReactServerContext<T> = (usable: any); | ||
return readContext(context); | ||
} | ||
} | ||
|
||
|
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.
Maybe add a comment explaining why this is necessary