found-relay
Version:
Relay integration for found
66 lines (54 loc) • 1.49 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = renderElement;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
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.default.createElement(Component, (0, _extends2.default)({
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
}));
}
module.exports = exports.default;