THIS IS ARCHIVED DOCUMENTATION

NotifyTrigger (Deprecated)

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.

Attributes

state

the state of the NotifyTrigger controller.

Properties

  • notification: string

    The notification to display to the user after receiving a notification trigger.

  • 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

Unsubscribe

Call signatures

  • (): void