--- title: Access Headless through Quantic slug: latest-access-headless canonical_url: https://docs.coveo.com/en/quantic/latest/usage/access-headless/ collection: quantic source_format: adoc --- # Access Headless through Quantic The Quantic library uses [Coveo Headless](https://docs.coveo.com/en/headless/latest) to interface with the [Coveo Platform](https://docs.coveo.com/en/186/). For advanced customizations not possible in Quantic components, you can leverage the Headless library directly through Quantic. This article provides an example meant to help you do so. The following is the JavaScript file of an example Quantic component that wraps the Headless [context](https://docs.coveo.com/en/headless/latest/reference/interfaces/Search.Context.html) controller to pass custom context. ```typescript // setContext.js import { LightningElement, api } from 'lwc'; import { registerComponentForInit, initializeWithHeadless } from 'c/quanticHeadlessLoader'; <1>   export default class MyCustomContextComponent extends LightningElement { @api engineId = 'my-search-page'; <2>   contextController; <3>   connectedCallback() { <4> registerComponentForInit(this, this.engineId); }   renderedCallback() { <5> initializeWithHeadless(this, this.engineId, this.initialize); }   initialize = (engine) => { this.contextController = CoveoHeadless.buildContext(engine); <6> this.contextController.set({ <7> ageGroup: '30-45', interests: ['sports', 'camping', 'electronics'] }); } } ``` <1> Two functions you'll need to connect your component with Coveo Headless. <2> Define the Headless engine ID property and assign it a default value. The [`@api` decorator](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_decorators) lets you expose that parameter publicly, making it accessible by parent components. In the end, the engine ID used by your `setContext` component must be the same as the one used by the components whose context you want to modify. <3> The variable you'll use as a context controller. <4> You must define this callback and the following one when wrapping Headless components to connect your components with the Headless state. The `registerComponentForInit` function registers your component for future initialization using the specified engine. <5> The `initializeWithHeadless` callback will execute your `initialize` function after the engine instance is created. This reliably sets the context before your interface sends a query or logs an event. <6> The Headless [`buildContext`](https://docs.coveo.com/en/headless/latest/reference/functions/Search.buildContext.html) method returns a context controller attached to your Headless engine. <7> Set the target context with your controller. Once included in the target pages, this component passes custom context when making search requests and logging [Coveo Analytics events](https://docs.coveo.com/en/260/). ```json // ... "context": { "ageGroup":"30-45", "interests" :["sports","camping","electronics"] }, // ... ``` > **Leading practice** > > Since the Coveo Quantic components wrap Headless components, you can have a look at the [Quantic components themselves](https://github.com/coveo/ui-kit/tree/main/packages/quantic/force-app/main/default/lwc) to see more examples.