Skip to content

Custom adapter

Usage

To create a custom adapter, you can create a new CustomAdapter class and implement the consume function.

import { CustomAdapter } from "@frend-digital/events/client";
export const customAdapter = new CustomAdapter((e) => {
switch (e.event) {
case "myCustomEvent":
// Handle the event
break;
}
});

Pushing the custom events

You can push custom events to the store using the dispatch function.

import { store } from "@frend-digital/events";
store.dispatch({
event: "myCustomEvent",
data: {
userId: 1,
name: "John Doe",
},
});

Example - logging all events

Events.tsx

import { CustomAdapter, EventSubscription } from "@frend-digital/events/client";
import { centraGTMAdapter } from "@frend-digital/events/gtm";
import { useState } from "react";
const logger = new CustomAdapter((e) => {
console.log(e.event, e.data);
});
const Events = () => {
const [adapters] = useState(() => [centraGTMAdapter(), logger]);
return <EventSubscription adapters={adapters} />;
};
export default Events;