UNPKG

@selfcommunity/react-core

Version:

React Core Components useful for integrating UI Community components (react-ui).

51 lines (49 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSCNotification = exports.SCNotificationContext = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const useSCWebSocket_1 = tslib_1.__importDefault(require("../../../hooks/useSCWebSocket")); const useSCWebPushMessaging_1 = tslib_1.__importDefault(require("../../../hooks/useSCWebPushMessaging")); const useSCMobileNativePushMessaging_1 = tslib_1.__importDefault(require("../../../hooks/useSCMobileNativePushMessaging")); /** * Creates Global Context * :::tip Context can be consumed in one of the following ways: ```jsx 1. <SCNotificationContext.Consumer>{(wsInstance, subscribe,) => (...)}</SCNotificationContext.Consumer> ``` ```jsx 2. const scNotificationContext: SCNotificationContextType = useContext(SCNotificationContext); ``` ```jsx 3. const scNotificationContext: SCNotificationContextType = useSCNotification(); ```` ::: */ exports.SCNotificationContext = (0, react_1.createContext)({}); /** * #### Description: * This component makes the notification context available down the React tree. * @param children * @return * ```jsx * <SCNotificationContext.Provider value={{wsInstance}}>{children}</SCNotificationContext.Provider> * ``` */ function SCNotificationProvider({ children = null }) { const { wsInstance } = (0, useSCWebSocket_1.default)(); const { wpSubscription } = (0, useSCWebPushMessaging_1.default)(); const { mnpmInstance } = (0, useSCMobileNativePushMessaging_1.default)(); return (0, jsx_runtime_1.jsx)(exports.SCNotificationContext.Provider, Object.assign({ value: { wsInstance, wpSubscription, mnpmInstance } }, { children: children })); } exports.default = SCNotificationProvider; /** * Let's only export the `useSCNotification` hook instead of the context. * We only want to use the hook directly and never the context component. */ function useSCNotification() { return (0, react_1.useContext)(exports.SCNotificationContext); } exports.useSCNotification = useSCNotification;