Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ContextToUse = useMemo(() => {
// Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.
// Memoize the check that determines which context instance we should use.
return propsContext &&
propsContext.Consumer &&
isContextConsumer()
? propsContext
: Context;
}, [propsContext, Context]);
function prepareElement(element, context) {
if (element === null || typeof element !== 'object') {
return Promise.resolve([null, context]);
}
const {type, props} = element;
if (isContextConsumer(element)) {
return Promise.resolve([props.children(type._currentValue), context]);
}
if (isContextProvider(element)) {
type._context._currentValue = props.value;
return Promise.resolve([props.children, context]);
}
if (typeof type === 'string' || isFragment(element)) {
return Promise.resolve([props.children, context]);
}
if (!isReactCompositeComponent(type)) {
return Promise.resolve([type(props, context), context]);
}
const CompositeComponent = type;
const instance = new CompositeComponent(props, context);
instance.props = props;
instance.context = context;
isContextConsumer(type) {
return !!type && isContextConsumer(makeFakeElement(type));
}
isCustomComponent(type) {
const fakeElement = makeFakeElement(type);
return !!type && (
typeof type === 'function'
|| isForwardRef(fakeElement)
|| isContextProvider(fakeElement)
|| isContextConsumer(fakeElement)
);
}
isCustomComponent(type) {
const fakeElement = makeFakeElement(type);
return !!type && (
typeof type === 'function'
|| isForwardRef(fakeElement)
|| isContextProvider(fakeElement)
|| isContextConsumer(fakeElement)
|| isSuspense(fakeElement)
);
}
isContextConsumer(type) {
return !!type && isContextConsumer(makeFakeElement(type));
}