UNPKG

@bemit/consent-ui-react

Version:

22 lines 775 B
import React from 'react'; import { useConsent } from '@bemit/consent-ui-react/ConsentUiProvider'; export const useEmbedState = service => { const { userPrefers, localeConsent, locale } = useConsent(); const [tmpConsent, setTmpConsent] = React.useState(undefined); const serviceInfo = locale ? localeConsent[locale]?.services?.find(s => s.id === service) : undefined; const allowsEmbed = serviceInfo ? userPrefers?.groups?.[serviceInfo.group] || userPrefers?.services?.[service] : undefined; React.useEffect(() => { if (allowsEmbed) { setTmpConsent(t => t === 1 ? 1 : allowsEmbed); } }, [setTmpConsent, allowsEmbed]); return { serviceConsent: tmpConsent, setServiceConsent: setTmpConsent, serviceInfo: serviceInfo }; };