init commit for iPAL-kit plugin
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
'use client'
|
||||
import { createContext, type ReactNode, use } from 'react'
|
||||
|
||||
import type { ConsentTexts } from './texts.js'
|
||||
|
||||
import { useConsent } from './useConsent.js'
|
||||
|
||||
type ConsentContextValue = { texts: ConsentTexts } & ReturnType<typeof useConsent>
|
||||
|
||||
const ConsentContext = createContext<ConsentContextValue | null>(null)
|
||||
|
||||
export function ConsentProvider({ children, texts }: { children: ReactNode; texts: ConsentTexts }) {
|
||||
const consent = useConsent()
|
||||
return <ConsentContext value={{ ...consent, texts }}>{children}</ConsentContext>
|
||||
}
|
||||
|
||||
export function useConsentContext(): ConsentContextValue {
|
||||
const ctx = use(ConsentContext)
|
||||
if (!ctx) {throw new Error('useConsentContext must be used within ConsentProvider')}
|
||||
return ctx
|
||||
}
|
||||
Reference in New Issue
Block a user