Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developers.hubspot.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

Hooks are used to simplify accessing context, performing actions, and fetching CRM data within UI extensions. The hooks provided by the UI extensions SDK are optimized to prevent unnecessary re-renders and automatically clean up resources when components unmount. You can pass inline arrays and objects to the hooks directly, as memoization is not required.

Universal hooks

Universal hooksSupported in all extension points: crm.record.tab, crm.record.sidebar, crm.preview, helpdesk.sidebar, settings, home
HookDescription
useExtensionApiAccess both context and actions from a single hook.
useExtensionContextAccess contextual information about the extension environment.
useExtensionActionsAccess actions that can be performed within HubSpot.
useCrmSearchSearch CRM records by query or structured filters.
import {
  useExtensionApi,
  // OR
  useExtensionContext,
  useExtensionActions,
  useCrmSearch
} from "@hubspot/ui-extensions";

useExtensionApi

The useExtensionApi hook provides access to available actions and contextual information from a single hook, for extension components that need access to both actions and context. Otherwise, it’s best practice to use the more specific useExtensionActions or useExtensionContext, depending on your use case. The following example uses the useExtensionApi hook to display an alert (action) containing the user’s first name (context) when a button is clicked.
import { Button, hubspot, useExtensionApi } from '@hubspot/ui-extensions';

hubspot.extend(() => <MyExtension />);

function MyExtension() {
  const { actions, context } = useExtensionApi();

  return (
    <Button onClick={() => actions.addAlert({ message: `Hello ${context.user.firstName}!` })}>
      Click me
    </Button>
  );
}

useExtensionContext

The useExtensionContext hook provides access to contextual information about the current extension environment, including location and other relevant data. For a complete list of available context properties, see the context reference documentation. The following example accesses the current extension location and renders it in a Text component:
import { Text, hubspot, useExtensionContext } from '@hubspot/ui-extensions';

hubspot.extend(() => <MyExtension />);

function MyExtension() {
  const context = useExtensionContext();

  return (
    <Text>Current location: {context.location}</Text>
  );
}

useExtensionActions

The useExtensionActions hook provides access to various actions that can be performed within the HubSpot interface. It’s a generic hook that can be typed with specific extension point locations for better TypeScript support. For a complete list of available actions, see the actions reference documentation. The actions available depend on the extension point location. The following example displays an alert when a button is clicked:
import { Button, hubspot, useExtensionActions } from '@hubspot/ui-extensions';

hubspot.extend(() => <MyExtension />);

function MyExtension() {
  const { addAlert } = useExtensionActions();

  return (
    <Button onClick={() => addAlert({ message: "Action completed!" })}>
      Click me
    </Button>
  );
}

useCrmSearch

The useCrmSearch hook searches CRM records of a given object type. The search is built using any combination of text query and structured filters, and returns record IDs, formatted properties, and optional associations.
useCrmSearch(
  {
    objectType: "contact",
    properties: ["firstname", "lastname", "email"],
    query: "john",
    filterGroups: [
      {
        filters: [
          { propertyName: "createdate", operator: "GT", value: "1704067200000" }
        ]
      }
    ],
    sorts: [{ propertyName: "createdate", direction: "DESCENDING" }],
    pageLength: 20,
  },
  {
    propertiesToFormat: "all",
    formattingOptions: {
      date: {
        format: "MM-DD-YYYY",
        relative: false,
      },
      dateTime: {
        format: "MM-DD-YYYY hh:mm",
        relative: false,
      },
      currency: {
        addSymbol: true,
      },
    },
  }
);
config
object
required
Configures the search request with:
  • objectType (required): the object type to search. Accepts type IDs ("0-1"), names ("contact", "deal"), or custom object names with a p_ prefix ("p_pets").
  • properties: an optional array of properties to return for each result.
  • query: an optional free-text search query matched against the object’s default searchable properties.
  • filterGroups: an optional array of filter groups. Groups in the array are OR’d together; filters within a single group are AND’d. Each filter includes a propertyName, an operator (EQ, NEQ, LT, LTE, GT, GTE, BETWEEN, IN, NOT_IN, HAS_PROPERTY, NOT_HAS_PROPERTY, CONTAINS_TOKEN, NOT_CONTAINS_TOKEN), and a value, values, or highValue field depending on the operator. See search the CRM for more details.
  • sorts: an optional array of sort configurations. Each item requires a propertyName and a direction ("ASCENDING" or "DESCENDING").
  • pageLength: an optional number of results per page. Default: 10. Max: 200.
propertiesToFormat
'all' | array
Either 'all' or an array of property names to format.
formattingOptions
object
Contains formatting options for the values returned from date, datetime, and currency properties.
  • The date and dateTime objects can include format and relative subfields:
    • format (string): a date or datetime string like MM-DD-YYYY or MM-DD-YYYY:mm:ss. Supports standard date time string formats.
    • relative (boolean): set to true to display the amount of time passed since the returned value (e.g., (1 day ago) or (1 hour ago)).
  • The currency object can include addSymbol (boolean), which sets whether the currency symbol should display with the number. Set to true to display the currency symbol.
Please note: formatting is applied based on property type (date, datetime, currency) rather than content. For example, date formatting will not apply to a string type property containing a date value.

CRM-specific hooks

These hooks are only available in CRM extension points (crm.record.tab, crm.record.sidebar, crm.preview, and helpdesk.sidebar).
import {
  useCrmProperties,
  useAssociations
} from "@hubspot/ui-extensions/crm";

useCrmProperties

The useCrmProperties hook fetches properties from the current CRM record with optional formatting. It accepts an array of properties to fetch, along with an optional object to format the returned data.
useCrmProperties(["firstname", "lastname", "email"], {
  propertiesToFormat: "all",
  formattingOptions: {
    date: {
      format: "MM-DD-YYYY",
      relative: false,
    },
    dateTime: {
      format: "MM-DD-YYYY hh:mm",
      relative: false,
    },
    currency: {
      addSymbol: true,
    },
  },
});
propertiesToFormat
'all' | array
required
Either 'all' or an array of property names to format.
formattingOptions
object
Contains formatting options for the values returned from date, datetime, and currency properties.
  • The date and dateTime objects can include format and relative subfields:
    • format (string): a date or datetime string like MM-DD-YYYY or MM-DD-YYYY:mm:ss. Supports standard date time string formats.
    • relative (boolean): set to true to display the amount of time passed since the returned value (e.g., (1 day ago) or (1 hour ago)).
  • The currency object can include addSymbol (boolean), which sets whether the currency symbol should display with the number. Set to true to display the currency symbol.
Formatting is applied based on property type (date, datetime, currency) rather than content. For example, date formatting will not apply to a string type property containing a date value.

useAssociations

The useAssociations hook fetches CRM records of a specific object type associated with the currently displaying record. It accepts an object containing configuration details for the association fetch request, and an optional object that formats returned property data.
useAssociations(
  {
    // Object type ID to fetch associations for
    toObjectType: "0-1",
    // Optional properties to fetch from associated records
    properties: ["firstname", "lastname", "email", "phone"],
    // Optional pagination settings
    pageLength: 25,
  },
  // Optional formatting configuration (same as useCrmProperties)
  {
    propertiesToFormat: "all",
    formattingOptions: {
      date: {
        format: "MM-DD-YYYY",
        relative: false,
      },
      dateTime: {
        format: "MM-DD-YYYY hh:mm",
        relative: false,
      },
      currency: {
        addSymbol: true,
      },
    },
  }
);
config
object
required
Configures the association data fetch request with:
  • toObjectType: the object type ID to fetch associations from (e.g., ‘0-1’ for contacts).
  • properties: an optional array of properties to fetch from associated records.
  • pageLength: an optional number of items per page (defaults to 10).
propertiesToFormat
'all' | array
required
Either 'all' or an array of property names to format.
formattingOptions
object
Contains formatting options for the values returned from date, datetime, and currency properties.
  • The date and dateTime objects can include format and relative subfields:
    • format (string): a date or datetime string like MM-DD-YYYY or MM-DD-YYYY:mm:ss. Supports standard date time string formats.
    • relative (boolean): set to true to display the amount of time passed since the returned value (e.g., (1 day ago) or (1 hour ago)).
  • The currency object can include addSymbol (boolean), which sets whether the currency symbol should display with the number. Set to true to display the currency symbol.

Best practices

Always use TypeScript generics

// ✅ Good - Typed for better IntelliSense and type safety
const actions = useExtensionActions<'crm.record.tab'>();
const context = useExtensionContext<'crm.record.tab'>();

// ❌ Avoid - Less type safety and IntelliSense
const actions = useExtensionActions();
const context = useExtensionContext();

Extract hook calls to component level

// ✅ Good - Hooks at component level
function MyExtension() {
  const { addAlert } = useExtensionActions<'crm.record.tab'>();
  const context = useExtensionContext<'crm.record.tab'>();

  const handleClick = () => {
    addAlert({ message: `Action from ${context.location}` });
  };

  return <Button onClick={handleClick}>Click me</Button>;
}

// ❌ Avoid - Don't call hooks in event handlers
function MyExtension() {
  const handleClick = () => {
    const { addAlert } = useExtensionActions(); // Wrong!
    addAlert({ message: "Hello" });
  };

  return <Button onClick={handleClick}>Click me</Button>;
}
Last modified on May 20, 2026