NotifyTrigger
NotifyTrigger
This is for:
DeveloperIn this article
Example Implementation
notify-trigger.fn.tsx
import {NotifyTrigger as HeadlessNotifyTrigger} from '@coveo/headless';
import {useEffect, useState, FunctionComponent} from 'react';
interface HeadlessNotifyTriggerProps {
controller: HeadlessNotifyTrigger;
}
export const NotifyTrigger: FunctionComponent<HeadlessNotifyTriggerProps> = (
props
) => {
const {controller} = props;
const [state, setState] = useState(controller.state);
useEffect(() => controller.subscribe(() => updateState()), []);
useEffect(() => notify(), [state.notifications]);
const updateState = () => {
setState(props.controller.state);
};
const notify = () => {
state.notifications.forEach((notification) => {
alert('Notification: ' + notification);
});
};
return null;
};
// usage
/**
* ```tsx
* const controller = buildNotifyTrigger(engine);
*
* <NotifyTriggerFn controller={controller} />;
* ```
*/
The NotifyTrigger
controller handles notify triggers. A [Notify trigger] (https://docs.coveo.com/en/3413#notify) query pipeline rule lets you define a message to be displayed to the end user when a certain condition is met.
Methods
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => void
A callback that’s invoked on state change.
Returns Unsubscribe
: A function to remove the listener.
Attributes
state
the state of the NotifyTrigger
controller.
Properties
-
notifications:
string[]
The notifications to display to the user after receiving notification triggers.
Initialize
buildNotifyTrigger
Creates a NotifyTrigger
controller instance.
Parameters
-
engine:
SearchEngine
The headless engine.
Returns NotifyTrigger
Related Types
Unsubscribe
Call signatures
-
(): void;