UNPKG

@tanstack/react-db

Version:

React integration for @tanstack/db

1 lines 978 B
{"version":3,"file":"DbProvider.cjs","sources":["../../src/DbProvider.tsx"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\nimport type { DbClient } from '@tanstack/db'\nimport type { ReactNode } from 'react'\n\nconst DbContext = createContext<DbClient | undefined>(undefined)\n\nexport type DbProviderProps = {\n client: DbClient\n children?: ReactNode\n}\n\nexport function DbProvider(props: DbProviderProps) {\n return (\n <DbContext.Provider value={props.client}>\n {props.children}\n </DbContext.Provider>\n )\n}\n\nexport function useDbClient(): DbClient {\n const client = useContext(DbContext)\n if (!client) {\n throw new Error(`useDbClient must be used within a DbProvider.`)\n }\n return client\n}\n\nexport function useOptionalDbClient(): DbClient | undefined {\n return useContext(DbContext)\n}\n"],"names":[],"mappings":";;;;;AAMA;AAOO;AACL;AAKF;AAEO;AACL;AACA;AACE;AAA+D;AAEjE;AACF;AAEO;AACL;AACF;;;;"}