UNPKG

@tapcart/app-studio-components

Version:

A library for accessing global components across different environments with a consistent API

26 lines (25 loc) 877 B
import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useContext } from 'react'; // Create a context for components const ComponentContext = createContext({}); /** * Hook to access global components * @returns Record of available components */ export function useComponents() { return useContext(ComponentContext); } /** * Provider component that makes components available via useComponents hook */ export function ComponentProvider({ children, componentSource }) { return (_jsx(ComponentContext.Provider, Object.assign({ value: componentSource }, { children: children }))); } /** * Helper function to create a component source from a map of components * @param components Map of component names to component implementations * @returns Component source object */ export function createComponentSource(components) { return components; }