Skip to content

Commit 300fe29

Browse files
committed
Add React.unstable_getCacheForType
1 parent 1e7e5a9 commit 300fe29

File tree

8 files changed

+15
-12
lines changed

8 files changed

+15
-12
lines changed

packages/react-fetch/src/ReactFetchBrowser.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type {Wakeable} from 'shared/ReactTypes';
1111

12-
import * as React from 'react';
12+
import {unstable_getCacheForType} from 'react';
1313

1414
const Pending = 0;
1515
const Resolved = 1;
@@ -35,12 +35,8 @@ type Result = PendingResult | ResolvedResult | RejectedResult;
3535
// TODO: this is a browser-only version. Add a separate Node entry point.
3636
const nativeFetch = window.fetch;
3737

38-
const ReactCurrentDispatcher =
39-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
40-
.ReactCurrentDispatcher;
41-
4238
function getResultMap(): Map<string, Result> {
43-
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
39+
return unstable_getCacheForType(createResultMap);
4440
}
4541

4642
function createResultMap(): Map<string, Result> {

packages/react-fetch/src/ReactFetchNode.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {Wakeable} from 'shared/ReactTypes';
1111

1212
import * as http from 'http';
1313
import * as https from 'https';
14-
import * as React from 'react';
14+
import {unstable_getCacheForType} from 'react';
1515

1616
type FetchResponse = {|
1717
// Properties
@@ -74,12 +74,8 @@ type RejectedResult = {|
7474

7575
type Result<V> = PendingResult | ResolvedResult<V> | RejectedResult;
7676

77-
const ReactCurrentDispatcher =
78-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
79-
.ReactCurrentDispatcher;
80-
8177
function getResultMap(): Map<string, Result<FetchResponse>> {
82-
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
78+
return unstable_getCacheForType(createResultMap);
8379
}
8480

8581
function createResultMap(): Map<string, Result<FetchResponse>> {

packages/react/index.classic.fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export {
5050
startTransition as unstable_startTransition,
5151
SuspenseList,
5252
SuspenseList as unstable_SuspenseList,
53+
unstable_getCacheForType,
5354
// enableScopeAPI
5455
unstable_Scope,
5556
unstable_useOpaqueIdentifier,

packages/react/index.experimental.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export {
4545
startTransition as unstable_startTransition,
4646
SuspenseList as unstable_SuspenseList,
4747
unstable_useOpaqueIdentifier,
48+
unstable_getCacheForType,
4849
// enableDebugTracing
4950
unstable_DebugTracingMode,
5051
} from './src/React';

packages/react/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ export {
8282
unstable_createFundamental,
8383
unstable_Scope,
8484
unstable_useOpaqueIdentifier,
85+
unstable_getCacheForType,
8586
} from './src/React';

packages/react/index.modern.fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export {
4949
startTransition as unstable_startTransition,
5050
SuspenseList,
5151
SuspenseList as unstable_SuspenseList,
52+
unstable_getCacheForType,
5253
// enableScopeAPI
5354
unstable_Scope,
5455
unstable_useOpaqueIdentifier,

packages/react/src/React.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {lazy} from './ReactLazy';
3333
import {forwardRef} from './ReactForwardRef';
3434
import {memo} from './ReactMemo';
3535
import {
36+
getCacheForType,
3637
useCallback,
3738
useContext,
3839
useEffect,
@@ -110,6 +111,7 @@ export {
110111
useDeferredValue,
111112
REACT_SUSPENSE_LIST_TYPE as SuspenseList,
112113
REACT_LEGACY_HIDDEN_TYPE as unstable_LegacyHidden,
114+
getCacheForType as unstable_getCacheForType,
113115
// enableFundamentalAPI
114116
createFundamental as unstable_createFundamental,
115117
// enableScopeAPI

packages/react/src/ReactHooks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ function resolveDispatcher() {
3636
return dispatcher;
3737
}
3838

39+
export function getCacheForType<T>(resourceType: () => T): T {
40+
const dispatcher = resolveDispatcher();
41+
return dispatcher.getCacheForType(resourceType);
42+
}
43+
3944
export function useContext<T>(
4045
Context: ReactContext<T>,
4146
unstable_observedBits: number | boolean | void,

0 commit comments

Comments
 (0)