UNPKG

@commercelayer/react-components

Version:
2 lines 488 B
"use client"; import{useContext}from"react";export default function useCustomContext({context,key,currentComponentName,contextComponentName}){const currentContext=useContext(context),isProduction=process.env.NODE_ENV==="production",msg=`Cannot use <${currentComponentName}/> outside of <${contextComponentName}/>`;if(key!=null&&key in currentContext||key==null&&currentContext!=null)return currentContext;if(isProduction)console.error(msg);else throw new Error(msg);return currentContext}