@appbuckets/react-ui-smart-components
Version:
UI Extended Components that work with @appbuckets/react-client and @appbuckets/react-ui
37 lines (34 loc) • 944 B
JavaScript
import { __spreadArray, __read, __assign } from '../../_virtual/_tslib.js';
import * as React from 'react';
import QuerySuspendedComponent from '../QuerySuspendedComponent.js';
/* --------
* HOC Definition
* -------- */
function asSuspendedComponent(Component, useQuery, queryArgs, config) {
return function SuspendedWithHOC(props) {
// ----
// Get Query Args
// ----
var useQueryArgs =
typeof queryArgs === 'function' ? queryArgs(props) : queryArgs;
// ----
// Execute Query
// ----
var useQueryResult = useQuery.apply(
void 0,
__spreadArray([], __read(useQueryArgs), false)
);
// ----
// Component Render
// ----
return React.createElement(
QuerySuspendedComponent,
__assign(__assign({}, config), {
Component: Component,
query: useQueryResult,
innerProps: props,
})
);
};
}
export { asSuspendedComponent as default };