MCPcopy Index your code
hub / github.com/reactjs/react-rails / createContext

Function createContext

lib/assets/react-source/development/react.js:1650–1756  ·  view source on GitHub ↗
(defaultValue, calculateChangedBits)

Source from the content-addressed store, hash-verified

1648 }
1649
1650 function createContext(defaultValue, calculateChangedBits) {
1651 if (calculateChangedBits === undefined) {
1652 calculateChangedBits = null;
1653 } else {
1654 {
1655 if (calculateChangedBits !== null && typeof calculateChangedBits !== 'function') {
1656 error('createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits);
1657 }
1658 }
1659 }
1660
1661 var context = {
1662 $$typeof: REACT_CONTEXT_TYPE,
1663 _calculateChangedBits: calculateChangedBits,
1664 // As a workaround to support multiple concurrent renderers, we categorize
1665 // some renderers as primary and others as secondary. We only expect
1666 // there to be two concurrent renderers at most: React Native (primary) and
1667 // Fabric (secondary); React DOM (primary) and React ART (secondary).
1668 // Secondary renderers store their context values on separate fields.
1669 _currentValue: defaultValue,
1670 _currentValue2: defaultValue,
1671 // Used to track how many concurrent renderers this context currently
1672 // supports within in a single renderer. Such as parallel server rendering.
1673 _threadCount: 0,
1674 // These are circular
1675 Provider: null,
1676 Consumer: null
1677 };
1678 context.Provider = {
1679 $$typeof: REACT_PROVIDER_TYPE,
1680 _context: context
1681 };
1682 var hasWarnedAboutUsingNestedContextConsumers = false;
1683 var hasWarnedAboutUsingConsumerProvider = false;
1684
1685 {
1686 // A separate object, but proxies back to the original context object for
1687 // backwards compatibility. It has a different $$typeof, so we can properly
1688 // warn for the incorrect usage of Context as a Consumer.
1689 var Consumer = {
1690 $$typeof: REACT_CONTEXT_TYPE,
1691 _context: context,
1692 _calculateChangedBits: context._calculateChangedBits
1693 }; // $FlowFixMe: Flow complains about not setting a value, which is intentional here
1694
1695 Object.defineProperties(Consumer, {
1696 Provider: {
1697 get: function () {
1698 if (!hasWarnedAboutUsingConsumerProvider) {
1699 hasWarnedAboutUsingConsumerProvider = true;
1700
1701 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?');
1702 }
1703
1704 return context.Provider;
1705 },
1706 set: function (_Provider) {
1707 context.Provider = _Provider;

Callers

nothing calls this directly

Calls 1

errorFunction · 0.70

Tested by

no test coverage detected