UNPKG

@kobalte/core

Version:

Unstyled components and primitives for building accessible web apps and design systems with SolidJS.

30 lines (22 loc) 783 B
import { createContext, useContext } from "solid-js"; import type { DomCollectionItem } from "./types"; export interface DomCollectionContextValue< T extends DomCollectionItem = DomCollectionItem, > { registerItem: (item: T) => () => void; } export const DomCollectionContext = createContext<DomCollectionContextValue>(); export function useOptionalDomCollectionContext() { return useContext(DomCollectionContext); } export function useDomCollectionContext< T extends DomCollectionItem = DomCollectionItem, >() { const context = useOptionalDomCollectionContext(); if (context === undefined) { throw new Error( "[kobalte]: `useDomCollectionContext` must be used within a `DomCollectionProvider` component", ); } return context as DomCollectionContextValue<T>; }