import { createContext, createMemo, Show, useContext, type ParentProps, type Accessor } from "solid-js" export function createSimpleContext>(input: { name: string init: ((input: Props) => T) | (() => T) gate?: boolean }) { const ctx = createContext() return { provider: (props: ParentProps) => { const init = input.init(props) const gate = input.gate ?? true if (!gate) { return {props.children} } // Access init.ready inside the memo to make it reactive for getter properties const isReady = createMemo(() => { // @ts-expect-error const ready = init.ready as Accessor | boolean | undefined return ready === undefined || (typeof ready === "function" ? ready() : ready) }) return ( {props.children} ) }, use() { const value = useContext(ctx) if (!value) throw new Error(`${input.name} context must be used within a context provider`) return value }, } }