Skip to content

queryBus.off

The off method allows to remove a listener from the query similarly to how removeEventListener works for DOM events.

Input parameters

messageName

messageName is a mandatory parameter of the string type which represents the name of the targeted message.

listenerToRemove

listenerToRemove is a mandatory parameter of type TMessageListener which represents a callback that should be removed from the given query

Example

To remove a listener from any query of the Query Bus you can use the off method:

useStorefront(async (storefront) => {
    function myFunction(query) {
        console.log('Query:', query.name);
    }

    storefront.queryBus.on('query-name', myFunction);

    storefront.queryBus.off('query-name', myFunction);
});

Methods reference