@j2inn/app-react
Version:
React implementation of the j2inn-app framework
19 lines (18 loc) • 819 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/*
* Copyright (c) 2021, J2 Innovations. All Rights Reserved
*/
import { loadDefault } from '@j2inn/app';
import { lazy, useMemo } from 'react';
import { Loading } from '../Loading';
import { Suspense } from '../Suspense';
/**
* Renders a remote UI component. This should be used in conjunction with
* the `RemoteScript` component.
*/
export const RemoteComponent = ({ scope, module, ...props }) => {
// Only lazily reload the component when the scope and module change.
// All other properties passthrough to the child component.
const Component = useMemo(() => lazy(loadDefault(scope, module)), [scope, module]);
return (_jsx(Suspense, { fallback: _jsx(Loading, { padded: true }), children: _jsx(Component, { ...props }) }));
};