import { SetupResult } from './mud/setup' import { ReactNode, createContext, useContext } from 'react' const MUDContext = createContext(null) type Props = { children: ReactNode value: SetupResult } export const MUDProvider = ({ children, value }: Props) => { const currentValue = useContext(MUDContext) if (currentValue) throw new Error('MUDProvider can only be used once') return {children} } export const useMUD = () => { const value = useContext(MUDContext) if (!value) throw new Error('Must be used within a MUDProvider') return value }