Hooks

To allow the user to insert custom code (e.g. for navigation after page creation), the hook pattern has been introduced.

Through this pattern it is possible to register callbacks, which are then executed by the Frontend API. It can be used as follows:

import { EcomHooks } from 'fcecom-frontend-api-client';

type OpenStoreFrontUrlPayload = {
  id: string; // ID of the element to open. 
  name: string; // Display name of the element to open · Only passed when triggered via report.
  type: string; // Type of the element to open.
  url: string; // URL of the element to open in the storefront.
};

const handleHook = (payload: OpenStorefrontUrlHookPayload) => {
  // ... Custom logic
}

api.addHook(EcomHooks.OPEN_STOREFRONT_URL, handleHook);

// To remove the registered hook, pass the exact instance
api.removeHook(EcomHooks.OPEN_STOREFRONT_URL, handleHook);

Please note that all callbacks will receive a single object containing the parameters. Further available hooks are documented in the enumeration EcomHooks in the Technical Reference documentation.


Last update: January 30, 2023