Skip to main content

TanStack Start

Components

Import from c15t/tanstack-start

c15t/tanstack-start exports ConsentRoot and re-exports every component and hook from c15t/react. Import them from c15t/tanstack-start so your app has one import path. They behave the same as in a React app, and render on the server with the state the root loader resolved.

ComponentRendersReference
ConsentRootThe consent runtime, seeded with the root loader's stateBelow
ConsentBannerThe banner, when the policy asks for oneConsentBanner
ConsentDialogThe preference dialogConsentDialog
ConsentWidgetThe preference controls inline in a pageConsentWidget
ConsentDialogLinkA button that opens the dialog, for your footerConsentDialogLink
ConsentDialogTriggerA floating, draggable button that opens the dialog. ConsentDialogTriggerToolbar adds your own actions beside itConsentDialogTrigger
ConsentGateIts children only while a category is allowedConsentGate
ConsentThemeA <style> element with your theme tokensCustomize
DevTools from c15t/react/devtoolsA development panel for consent state and scriptsDevTools

Render every component inside ConsentRoot. Do not also mount ConsentProvider; ConsentRoot already renders one.

ConsentRoot

ConsentRoot wraps the app in the root route. It takes the state the root loader resolved on the server and creates the consent runtime from it, so the server HTML and the first browser render match. The quickstart shows it in context.

PropPurpose
stateRequired. The loader's consent state, a promise of it for a streamed loader, or {} for pages without a server render
scriptsConsent-gated vendor scripts. See scripts and embeds
vendorsVendors listed under their category with their own switch
networkBlockerRules that hold fetch and XMLHttpRequest calls until their category is allowed
clearOnRevocationCookies and storage keys to delete when a category is denied
persistenceStores the visitor's choice. On by default
scriptLoaderOptions for the script loader module
optionsAny other ConsentProvider option, such as theme, i18n, presentation, callbacks, consentCategories, reloadOnConsentRevoked or preloadDialog

The state carries the backend URL, the mode and the route prefix you passed to createConsentStateHandler, so ConsentRoot has no props for them. With state={{}}, it takes the backend URL from consentManifest() and uses manifest(). Without a backend URL from either, it throws, unless the mode is offline(). options.mode replaces the state's mode: manifest(), hosted() or offline() from c15t/tanstack-start, or a transport such as custom(transport).

ConsentRoot creates the runtime once, when it mounts, and ignores later changes to state. Keep it in the root route so client navigation never remounts it.

The root entry also exports consentPrefetchHead for pages without a server render, and buildPrefetchScript, the script builder behind it.

Server and other entry points

ImportExportsUse
c15t/tanstack-startmanifest, hosted, offlineThe modes, as data for createConsentStateHandler({ mode }). See consent modes
c15t/tanstack-start/servercreateConsentStateHandler, resolveConsent, consentLoaderOptions, mergeInitIntoConsentStateResolve the visitor's state in a server function. createConsentStateHandler takes mode, routePrefix, proxy, snapshot and the resolveConsent options
c15t/tanstack-start/middlewareconsentRequestMiddlewareRead location, language and privacy headers on every request. See geography headers
c15t/tanstack-start/apicreateConsentRouteServe /api/c15t/* from src/routes/api/c15t/$.ts
c15t/tanstack-start/buildconsentManifestVite plugin that bundles the manifest at build time. See the quickstart
c15t/generatedsnapshot, backendURLThe manifest and backend URL the plugin fetched. snapshot is undefined in the browser bundle
c15t/tanstack-start/staticcreateStaticConsentResolver, loadStaticManifest, createStaticManifestModule, resolveUnknownLocationInitLower-level helpers for a build-time manifest. See rendering
c15t/tanstack-start/headlessHeadless hooksCustom markup
c15t/tanstack-start/components/consent-dialog-linkConsentDialogLink onlyA module that needs the link without loading the rest of the adapter

resolveConsent is the function behind createConsentStateHandler. Call it directly from a server route or middleware that already holds the Request, and pass it as request. Import server, middleware and api only from server code.

IAB TCF components

Import IABProvider, IABConsentBanner and IABConsentDialog from c15t/react/iab, render them inside ConsentRoot next to ConsentBanner and ConsentDialog, and load c15t/tanstack-start/styles.css and c15t/tanstack-start/iab/styles.css with styles: false. The stock banner and dialog stay closed under an IAB policy. See IAB TCF.