UNPKG

@shopgate/engage

Version:
25 lines (24 loc) 802 B
import React from 'react'; import AppContext from "../contexts/AppContext"; /** * Injects the AppContext properties into the desired component within a prop named "app". * @param {Function} WrappedComponent The react component to wrap. * @returns {JSX} */ import { jsx as _jsx } from "react/jsx-runtime"; export function withApp(WrappedComponent) { /** * The actual HOC. * @param {Object} props The component props. * @returns {JSX} */ const WithApp = props => /*#__PURE__*/_jsx(AppContext.Consumer, { children: appContext => /*#__PURE__*/_jsx(WrappedComponent, { app: appContext, ...props }) }); const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component'; WithApp.displayName = `WithApp(${displayName})`; return WithApp; }