RecentQueriesList
RecentQueriesList
This is for:
DeveloperExample Implementation
recent-queries.fn.tsx
import {RecentQueriesList as HeadlessRecentQueriesList} from '@coveo/headless';
import {useEffect, useState} from 'react';
export interface RecentQueriesProps {
controller: HeadlessRecentQueriesList;
}
export const RecentQueriesList: React.FunctionComponent<RecentQueriesProps> = (
props
) => {
const {controller} = props;
const [state, setState] = useState(controller.state);
useEffect(() => controller.subscribe(() => setState(controller.state)), []);
return (
<div>
Recent queries:
<ul>
{state.queries.map((query) => (
<li key={query}>{query}</li>
))}
</ul>
</div>
);
};
The RecentQueriesList
controller manages the user’s recent queries.
Methods
clear
Clears the recent queries list.
executeRecentQuery
Executes the given recent query.
Parameters
-
index:
number
The index of the recent query to execute.
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 RecentQueriesList controller.
Properties
-
analyticsEnabled:
boolean
Whether analytics & tracking are enabled. In the case where it is disabled, it is recommended not to save recent queries.
-
maxLength:
number
The maximum number of queries to retain in the list.
-
queries:
string[]
The list of recent queries.
Initialize
buildRecentQueriesList
Creates a RecentQueriesList
controller instance.
Parameters
-
engine:
SearchEngine
The headless engine.
-
props:
RecentQueriesListProps
The configuration
RecentQueriesList
properties.
Returns RecentQueriesList
RecentQueriesListProps
The configuration RecentQueriesList
properties.
Properties
-
initialState?:
RecentQueriesListInitialState
The initial state that should be applied to the
RecentQueriesList
controller. -
options?:
RecentQueriesListOptions
The configuration options that should be applied to the
RecentQueriesList
controller.
RecentQueriesListInitialState
The initial state that should be applied to the RecentQueriesList
controller.
Properties
-
queries:
string[]
The list of recent queries.
Default:
[]
RecentQueriesListOptions
The configuration options that should be applied to the RecentQueriesList
controller.
Properties
-
maxLength:
number
The maximum number of queries to retain in the list.
Default:
10
-
clearFilters?:
boolean
Whether to clear all active query filters when the end user submits a new query from the recent queries list. Setting this option to "false" is not recommended & can lead to an increasing number of queries returning no results.
Related Types
Unsubscribe
Call signatures
-
(): void;