UNPKG

@talend/react-cmf

Version:

A framework built on top of best react libraries

56 lines (55 loc) 1.45 kB
import PropTypes from 'prop-types'; import componentAPI from './component'; import { useCMFContext } from './useContext'; /** * The Inject component let you use the registry to render named component * using the registry. It will not break the app if component is not found * but it will display an error. * @module react-cmf/lib/Inject * @example import { Inject } from '@talend/react-cmf'; // this is not the best example but it show the concept function MyComponent(props) { return ( <Inject component="Action" onClick={props.onClick}> <Inject component="Icon" icon={props.icon} /> </Inject> ); } */ import { jsx as _jsx } from "react/jsx-runtime"; function NotFoundComponent({ error }) { // eslint-disable-next-line no-console console.error(error); return /*#__PURE__*/_jsx("div", { className: "alert alert-danger", children: error.message }); } NotFoundComponent.propTypes = { error: PropTypes.string.isRequired }; function Inject({ component, ...props }) { const context = useCMFContext(); try { const Component = componentAPI.get(component, context); return /*#__PURE__*/_jsx(Component, { ...props }); } catch (error) { return /*#__PURE__*/_jsx(NotFoundComponent, { error: error }); } } Inject.propTypes = { component: PropTypes.string.isRequired }; Inject.NotFoundComponent = NotFoundComponent; export default Inject; //# sourceMappingURL=Inject.component.js.map