@amp-labs/react
and provides a powerful foundation for managing connections and installations while giving you complete control over your UI implementation. This library is designed for developers who want to build custom user interfaces while leveraging robust connection, integration, and installation management capabilities.
The Headless UI library is in beta. It may change in non-backwards-compatible ways. (Although we are very serious about semantic versioning.)If you have any feedback, please file an issue on Github.
Overview
The Headless UI Library provides a series of React hooks that manage connections, installations, and other configuration data using query and mutation hooks. The hooks may be used together or independently of the prebuilt UI components. The Headless UI Library separates the logic of connection and installation management from the UI components, allowing you to:- Manage connections to various services and platforms.
- Handle installation processes.
- Implement custom UI components.
- Maintain full control over the user experience.
Prerequisites
Install the library
The Headless UI Library is currently in the same package as our prebuilt UI components.Context setup
In order for the headless hooks and functions to have relevant context, you can only use them insideAmpersandProvider
and InstallationProvider
.
The AmpersandProvider
needs to wrap all usages of headless hooks and functions as well as prebuilt UI components. See Ampersand Provider for more details.
The InstallationProvider
needs to wrap any code that interacts with a particular installation. This means that if your UI needs to handle multiple installations (e.g., one for Asana and one for Zendesk), then you need two instances of InstallationProvider
: one that wraps the code for Asana setup, and one that wraps the code for Zendesk setup.
InstallationProvider
requires the following props:
- integration (string): the name of an integration that you’ve defined in
amp.yaml
. - consumerRef (string): the ID that your app uses to identify this end user.
- consumerName (string, optional): the display name for this end user.
- groupRef (string): the ID that your app uses to identify a company, team, or workspace. See group.
- groupName (string, optional): the display name for this group.
Connection management
The library provides hooks and utilities for managing Connections. TheuseConnection
hook provides access to the current connection state and management functions. It returns an object with the following properties:
connection
: The current Connection object, or null if there isn’t one.error
: Any error that occurred while fetching the Connection.isPending
: If true, there is no data yet.isFetching
: If true, the data is being fetched (including refetches).isError
: If true, an error occurred while fetching the connection.isSuccess
: If true, the last fetch was successful.
Installation management
Get current installation
TheuseInstallation
hook provides access to the current installation state and management functions. It returns an object with the following properties:
installation
: The current Installation object, or null if not installed.error
: Any error that occurred while fetching the Installation.isPending
: If true, there is no data yet.isFetching
: If true, the data is being fetched (including refetches).isError
: If true, an error occurred while fetching the connection.isSuccess
: If true, the last fetch was successful.
Get config from existing installation
To access the configuration from an existing installation, you can use theinstallation.config
property. See API reference for more details:
For more advanced config management: including getting/setting read/write objects in the config and managing a local draft copy, use the
useLocalConfig()
hook.Create, update, and delete installations
The following hooks provide granular control over Installation operations:useCreateInstallation
useUpdateInstallation
useDeleteInstallation
useCreateInstallation
hook is used to create a new Installation. It returns the following:
createInstallation
: a tanstack-query mutation function to create a new Installation. Its signature is:
isPending
: Boolean indicating if creation is in progress.error
: Any error that occurred during creation.errorMsg
: String message describing the error.isIdle
: If true,createInstallation
has not been called yet.isSuccess
: If true, installation was successfully created.
useUpdateInstallation
and useDeleteInstallation
follow similar conventions.
Here’s an example of how you can use these hooks:
Get manifest and field metadata
TheuseManifest
hook provides the data that you need to build input forms for your users to help them configure the integration. This hook allows you to:
- Access integrations as defined in the manifest (
amp.yaml
). - Retrieve object and field metadata from the connected provider (e.g., Salesforce, Hubspot). This allows your application to know about the exact objects and fields that exist in your customer’s SaaS instance, including custom objects and fields. With this information, you can build dropdowns, checkboxes, etc.
For now, you can only access your manifest’s Read Actions. Please note that you still create an Installation with Subscribe and Write Actions usinguseCreateInstallation
. For write actions, you can also useuseConfig
to construct the config object, see Manage write config.
Get fields from customer’s SaaS
ThegetCustomerFieldsForObject
function returned by useManifest
allows you to retrieve the standard and custom fields that exist in your customer’s SaaS instance for a particular object.
useManifest
to build the UI for customers to configure the installation.
Config management
Managing the Config that keeps track of each customer’s preference for how the integration behaves can be complex, with deeply nested objects and the need to manage this state locally. TheuseLocalConfig
hook simplifies local state management of the config object by providing flexible utilities to manipulate the config through a set of setters and getters. It maintains a draft state, which you can modify before committing changes to the installation.
Deprecated:
useConfig
has been deprecated in v2.9.0. It has been renamed to useLocalConfig()
without any other changes.For fetching an existing config from an installation, use useInstallation
which provides access to the current installation’s configuration.Basic example
This is a basic example that hard-codes a Config and does not allow the user to modify it.Manage read config
This is an example for how to use helper functions to more easily construct a read config, so you do not have to create the full config object manually.Manage write config
The headless UI library provides helper functions to more easily construct a write config. Here’s a simple example that enables a particular object to be written to:- Set default values for certain fields.
- Prevent overwriting of existing customer data.
Configure features individually
You can configure write settings for individual features using these methods:Configure features together
You can usesetFieldSettings
to set all advanced write features at once for a field:
Full example
Here’s a full example that uses theReadObjectConfig
and WriteObjectConfig
components defined above, and makes a call to updateInstallation
with the config that has now been updated with both read actions and write actions.
Examples
Demo app
View the source code on GitHub
- Ability to map fields; the dropdown is populated with standard and optional fields from the connected Salesforce instance.
- Ability to create and update an Installation with the “Install” button.
- Ability to reset Config to previous state with the “Reset” button.
- Ability to delete an Installation with the “Delete” button.
- Usage of Shadcn UI components + Tailwind CSS to demonstrate how you can bring your own design system.
- useConnection: manage when to show ConnectProvider
- useManifest: manage objects and metadata
- useConfig: manage installation configuration state
- useCreateInstallation, useUpdateInstallation, and useDeleteInstallation: manage installation lifecycle
Demo app with write config
View the source code on GitHub
- Ability to set default values for fields when writing.
- Ability to prevent overwriting of customer data.