{ "version": 3, "sources": ["../../../app/utils/react/context.ts"], "sourcesContent": ["import {\n createContext as rcCreateContext,\n useContext as rcUseContext,\n} from 'react';\n\nimport type { Maybe } from '~/typings/utils';\nimport type { CreateContextOptions, CreateContextReturn } from './react.types';\nimport { isNil } from 'lodash-es';\n\nconst CONTEXT_ERROR_MESSAGE =\n 'useContext must be inside a Provider with a value';\n\n/**\n * Creates a named context, provider, and hook. An effective way to create context.\n *\n * https://juliangaramendy.dev/blog/strict-react-context\n * https://kentcdodds.com/blog/how-to-use-react-context-effectively\n *\n * @param options create context options\n */\nconst createContext = (options: CreateContextOptions = {}) => {\n const { strict = true, errorMessage = CONTEXT_ERROR_MESSAGE, name } = options;\n\n const Context = rcCreateContext>(null);\n\n Context.displayName = name;\n\n const useContext = () => {\n const context = rcUseContext(Context);\n if (strict && isNil(context)) {\n throw new Error(errorMessage);\n }\n return context;\n };\n\n return [\n Context.Provider,\n useContext,\n Context,\n ] as CreateContextReturn;\n};\n\nexport default createContext;\n"], "mappings": "+JAAA,IAAAA,EAGO,SAMP,IAAMC,EACJ,oDAUIC,EAAgB,CAAcC,EAAgC,CAAC,IAAM,CACzE,GAAM,CAAE,OAAAC,EAAS,GAAM,aAAAC,EAAeJ,EAAuB,KAAAK,CAAK,EAAIH,EAEhEI,KAAU,EAAAC,eAAoC,IAAI,EAExDD,EAAQ,YAAcD,EAEtB,IAAMG,EAAa,IAAM,CACvB,IAAMC,KAAU,EAAAC,YAAaJ,CAAO,EACpC,GAAIH,GAAUQ,EAAMF,CAAO,EACzB,MAAM,IAAI,MAAML,CAAY,EAE9B,OAAOK,CACT,EAEA,MAAO,CACLH,EAAQ,SACRE,EACAF,CACF,CACF,EAEOM,EAAQX", "names": ["import_react", "CONTEXT_ERROR_MESSAGE", "createContext", "options", "strict", "errorMessage", "name", "Context", "rcCreateContext", "useContext", "context", "rcUseContext", "isNil_default", "context_default"] }