found-relay
Version:
Relay integration for found
55 lines (49 loc) • 1.23 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import React from 'react';
export default function renderElement({
/* eslint-disable react/prop-types */
match,
Component,
isComponentResolved,
hasComponent,
querySubscription,
resolving // Whether it's safe to throw a RedirectException or an HttpError.
}) {
const {
route,
router
} = match;
const {
readyState,
environment,
variables
} = querySubscription;
const {
error,
props
} = readyState;
if (!route.render) {
if (!isComponentResolved || !error && !props) {
return undefined;
}
if (!props || !hasComponent) {
if (process.env.NODE_ENV !== 'production') console.error(`Route with query \`${querySubscription.getQueryName()}\` has no render method or component.`);
return null;
} // @ts-ignore
return /*#__PURE__*/React.createElement(Component, _extends({
match: match,
router: router
}, props));
}
return route.render(Object.assign({}, readyState, {
match,
Component: isComponentResolved ? Component : null,
props: props && Object.assign({
match,
router
}, props),
environment,
variables,
resolving
}));
}