MCPcopy Index your code
hub / github.com/plotly/dash / createContext

Function createContext

dash/deps/react@18.2.0.js:1225–1337  ·  view source on GitHub ↗
(defaultValue)

Source from the content-addressed store, hash-verified

1223 }
1224
1225 function createContext(defaultValue) {
1226 // TODO: Second argument used to be an optional `calculateChangedBits`
1227 // function. Warn to reserve for future use?
1228 var context = {
1229 $$typeof: REACT_CONTEXT_TYPE,
1230 // As a workaround to support multiple concurrent renderers, we categorize
1231 // some renderers as primary and others as secondary. We only expect
1232 // there to be two concurrent renderers at most: React Native (primary) and
1233 // Fabric (secondary); React DOM (primary) and React ART (secondary).
1234 // Secondary renderers store their context values on separate fields.
1235 _currentValue: defaultValue,
1236 _currentValue2: defaultValue,
1237 // Used to track how many concurrent renderers this context currently
1238 // supports within in a single renderer. Such as parallel server rendering.
1239 _threadCount: 0,
1240 // These are circular
1241 Provider: null,
1242 Consumer: null,
1243 // Add these to use same hidden class in VM as ServerContext
1244 _defaultValue: null,
1245 _globalName: null
1246 };
1247 context.Provider = {
1248 $$typeof: REACT_PROVIDER_TYPE,
1249 _context: context
1250 };
1251 var hasWarnedAboutUsingNestedContextConsumers = false;
1252 var hasWarnedAboutUsingConsumerProvider = false;
1253 var hasWarnedAboutDisplayNameOnConsumer = false;
1254
1255 {
1256 // A separate object, but proxies back to the original context object for
1257 // backwards compatibility. It has a different $$typeof, so we can properly
1258 // warn for the incorrect usage of Context as a Consumer.
1259 var Consumer = {
1260 $$typeof: REACT_CONTEXT_TYPE,
1261 _context: context
1262 }; // $FlowFixMe: Flow complains about not setting a value, which is intentional here
1263
1264 Object.defineProperties(Consumer, {
1265 Provider: {
1266 get: function () {
1267 if (!hasWarnedAboutUsingConsumerProvider) {
1268 hasWarnedAboutUsingConsumerProvider = true;
1269
1270 error('Rendering <Context.Consumer.Provider> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Provider> instead?');
1271 }
1272
1273 return context.Provider;
1274 },
1275 set: function (_Provider) {
1276 context.Provider = _Provider;
1277 }
1278 },
1279 _currentValue: {
1280 get: function () {
1281 return context._currentValue;
1282 },

Callers

nothing calls this directly

Calls 2

errorFunction · 0.70
warnFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…