{"version":3,"file":"unstated-next.mjs","sources":["../src/unstated-next.tsx"],"sourcesContent":["import React from \"react\"\n\nexport interface ContainerProviderProps<State = void> {\n\tinitialState?: State\n\tchildren: React.ReactNode\n}\n\nexport interface Container<Value, State = void> {\n\tProvider: React.ComponentType<ContainerProviderProps<State>>\n\tuseContainer: () => Value\n}\n\nexport function createContainer<Value, State = void>(\n\tuseHook: (initialState?: State) => Value,\n): Container<Value, State> {\n\tlet Context = React.createContext<Value | null>(null)\n\n\tfunction Provider(props: ContainerProviderProps<State>) {\n\t\tlet value = useHook(props.initialState)\n\t\treturn <Context.Provider value={value}>{props.children}</Context.Provider>\n\t}\n\n\tfunction useContainer(): Value {\n\t\tlet value = React.useContext(Context)\n\t\tif (value === null) {\n\t\t\tthrow new Error(\"Component must be wrapped with <Container.Provider>\")\n\t\t}\n\t\treturn value\n\t}\n\n\treturn { Provider, useContainer }\n}\n\nexport function useContainer<Value, State = void>(\n\tcontainer: Container<Value, State>,\n): Value {\n\treturn container.useContainer()\n}\n"],"names":["createContainer","useHook","Context","React","createContext","Provider","props","value","initialState","children","useContainer","useContext","Error","container"],"mappings":";;SAYgBA,gBACfC;MAEIC,OAAO,GAAGC,KAAK,CAACC,aAAN,CAAkC,IAAlC,CAAd;;WAESC,QAAT,CAAkBC,KAAlB;QACKC,KAAK,GAAGN,OAAO,CAACK,KAAK,CAACE,YAAP,CAAnB;WACOL,mBAAA,CAACD,OAAO,CAACG,QAAT;MAAkBE,KAAK,EAAEA;KAAzB,EAAiCD,KAAK,CAACG,QAAvC,CAAP;;;WAGQC,YAAT;QACKH,KAAK,GAAGJ,KAAK,CAACQ,UAAN,CAAiBT,OAAjB,CAAZ;;QACIK,KAAK,KAAK,IAAd,EAAoB;YACb,IAAIK,KAAJ,CAAU,qDAAV,CAAN;;;WAEML,KAAP;;;SAGM;cAAEF,QAAF;kBAAYK;GAAnB;;AAGD,SAAgBA,aACfG;SAEOA,SAAS,CAACH,YAAV,EAAP;;;;;"}