Overview
Event listeners are used to observe and intercept actions taken inside the Embeddable UI. You might, for example, react to a user linking a bank account, or take over the library’s built-in behavior entirely. Listeners are shared across all instances of the Embeddable UI. Registrations across different components share the same state, and the last registration for a given key wins, so prefer a single registration site per event key to avoid conflicts. The available events are listed below under Reference.Use Cases
Event listeners open up a wide range of possibilities for tailoring the Embeddable UI to your platform. The examples below illustrate some common patterns.Invoice Routing
If your platform has its own invoicing, event listeners let you route users back to your invoices from within the Embeddable UI. For example, a vertical SaaS platform issues invoices through its own product, and the Tight Transactions Dashboard shows a payout that includes three of those invoices. When the user clicks on one of those invoices, you can intercept the click and route the user to the corresponding invoice in your platform instead.Paywall Enforcement
Event listeners also let you gate specific functionality behind your own pricing tiers. For example, a horizontal SaaS platform wants to offer Tax Estimates only on a paid plan. When a user clicks into tax-related functionality, the platform intercepts the routing and shows its own paywall screen instead of the built-in tax experience.Setting Listeners
Listeners are accessed via theuseEmbeddedEventListeners hook. Keep in mind that this must be used within a <Tight>
component. Listener declaration is done either by passing initial listeners to the hook, or by using the setListeners
function returned by it. This function accepts a subset of all possible listeners, and will merge any input into your
already defined listeners. This means that both this:
The initial listeners passed to
useEmbeddedEventListeners are only applied once, on mount. Re-renders do not
re-apply them. To update a listener after mount, use setListeners.Updating Listeners
SincesetListeners accepts a subset of listeners, you’re able to update your listeners at any time after mount. The
code below adds a gusto listener without affecting any previously registered keys.
Removing Listeners
If you want to remove a listener, passnull for its key. Unrelated keys are preserved.
Preventing Default Behavior
Each listener is registered as anEventRegistration, which pairs your callback with an optional preventDefault
flag. When preventDefault is true, the library’s built-in behavior for that event is suppressed (for example, the
Plaid modal will not open; the transaction drawer will not open). When false or omitted, both your listener and the
default behavior run.
For example, to open a bank’s website in a custom in-app browser instead of a new tab, suppress the default behavior
and handle the navigation yourself:
Handling Events
Every event is a discriminated union with aresult field:
event.result before reading data or error.
Reference
useEmbeddedEventListeners returns a [listeners, setListeners] tuple:
object
A snapshot of all currently registered listeners.
function
A function to merge new registrations into the existing state. Each key accepts an
EventRegistration, or null
to remove that listener.Events
Each row below is a registration key you can pass touseEmbeddedEventListeners. The Event types column lists the event.type values a single registration may receive, and the data and error shapes are the payloads on SUCCESS and FAILURE results respectively.
TypeScript
All types are exported from@tight-embedded/react: