const createContext = (name, defaultValue, { wrap = comp => comp } = {}) => { const CreatedContext = React.createContext(defaultValue); return { name, wrap: Component => withContext(CreatedContext, name)(wrap(Component)), Consumer: CreatedContext.Consumer, Provider: CreatedContext.Provider }; }
function createSubscriber() { return new Consumer(emitter); }
function useContext(Context, unstable_observedBits) { var dispatcher = resolveDispatcher(); { if (unstable_observedBits !== undefined) { error('useContext() second argument is reserved for future ' + 'use in React. Passing it is not supported. ' + 'You passed: %s.%s', unstable_observedBits, typeof unstable_observedBits === 'number' && Array.isArray(arguments[2]) ? '\n\nDid you call array.map(useContext)? ' + 'Calling Hooks inside a loop is not supported. ' + 'Learn more at https://fb.me/rules-of-hooks' : ''); } // TODO: add a more generic warning for invalid values. if (Context._context !== undefined) { var realContext = Context._context; // Don't deduplicate because this legitimately causes bugs // and nobody should be using this in existing code. if (realContext.Consumer === Context) { error('Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + 'removed in a future major release. Did you mean to call useContext(Context) instead?'); } else if (realContext.Provider === Context) { error('Calling useContext(Context.Provider) is not supported. ' + 'Did you mean to call useContext(Context) instead?'); } } } return dispatcher.useContext(Context, unstable_observedBits); }
if (context !== context.Consumer) { if (!hasWarnedAboutUsingContextAsConsumer) { hasWarnedAboutUsingContextAsConsumer = true;
return context.Consumer;
function createSubscriber(): any { return new Consumer(emitter); }