Crumbie

React Hooks

Programmatic access to consent state and actions.

useCookieConsent

Primary hook for reading and mutating consent.

tsx
import { useCookieConsent } from "crumbie"

const {
  consent,
  hasConsent,
  acceptAll,
  declineAll,
  updatePreferences,
  resetConsent,
  openSettings,
  closeSettings,
  isAllowed,
} = useCookieConsent()
  • consent — full storage record or null
  • hasConsent — whether a valid, non-expired record exists
  • acceptAll / declineAll — set all optional categories
  • updatePreferences — partial update (necessary stays true)
  • isAllowed(category) — boolean check for a category

useConsentCategory

Shortcut for gating a single category.

tsx
import { useConsentCategory } from "crumbie"

const analyticsEnabled = useConsentCategory("analytics")

if (analyticsEnabled) {
  // load analytics
}