UNPKG

1.32 kBJavaScriptView Raw
1import * as React from "rehackt";
2import { canUseSymbol } from "../../utilities/index.js";
3import { invariant } from "../../utilities/globals/index.js";
4// To make sure Apollo Client doesn't create more than one React context
5// (which can lead to problems like having an Apollo Client instance added
6// in one context, then attempting to retrieve it from another different
7// context), a single Apollo context is created and tracked in global state.
8var contextKey = canUseSymbol ? Symbol.for("__APOLLO_CONTEXT__") : "__APOLLO_CONTEXT__";
9export function getApolloContext() {
10 invariant("createContext" in React, 46);
11 var context = React.createContext[contextKey];
12 if (!context) {
13 Object.defineProperty(React.createContext, contextKey, {
14 value: (context = React.createContext({})),
15 enumerable: false,
16 writable: false,
17 configurable: true,
18 });
19 context.displayName = "ApolloContext";
20 }
21 return context;
22}
23/**
24 * @deprecated This function has no "resetting" effect since Apollo Client 3.4.12,
25 * and will be removed in the next major version of Apollo Client.
26 * If you want to get the Apollo Context, use `getApolloContext` instead.
27 */
28export var resetApolloContext = getApolloContext;
29//# sourceMappingURL=ApolloContext.js.map
\No newline at end of file