NotifyTrigger (Deprecated)
NotifyTrigger (Deprecated)
In this article
|
Headless v1 has been deprecated. We recommend using the latest version of the Coveo Headless library. |
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.notification]);
const updateState = () => {
setState(props.controller.state);
};
const notify = () => {
if (state.notification) {
alert('Notification: ' + state.notification);
}
};
return null;
};
// usage
/**
* ```tsx
* const controller = buildNotifyTrigger(engine);
*
* <NotifyTriggerFn controller={controller} />;
* ```
*/
The NotifyTrigger
controller handles Notify triggers.
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.
Was this article useful?
Thanks for your feedback!