showcase/shell-docs/src/content/reference/hooks/useSuggestions.mdx
useSuggestions is a React hook that provides access to the current chat suggestions for a given agent. It subscribes to suggestion changes and automatically re-renders when suggestions are updated, cleared, or reloaded.
Suggestions are configured via useConfigureSuggestions and can be either static (predefined) or dynamic (generated by the agent).
import { useSuggestions } from "@copilotkit/react-core/v2";
function useSuggestions(options?: UseSuggestionsOptions): UseSuggestionsResult;
function SuggestionsList() {
const { suggestions, isLoading } = useSuggestions();
if (isLoading) {
return <div>Loading suggestions...</div>;
}
return (
<ul>
{suggestions.map((suggestion, i) => (
<li key={i}>
<strong>{suggestion.title}</strong>
<p>{suggestion.message}</p>
</li>
))}
</ul>
);
}
function SuggestionsPanel() {
const { suggestions, reloadSuggestions, clearSuggestions, isLoading } =
useSuggestions();
return (
<div>
<div>
<button onClick={reloadSuggestions} disabled={isLoading}>
Refresh
</button>
<button onClick={clearSuggestions}>Clear</button>
</div>
{suggestions.map((suggestion, i) => (
<button key={i} disabled={suggestion.isLoading}>
{suggestion.title}
</button>
))}
</div>
);
}
function AgentSuggestions() {
const { suggestions } = useSuggestions({ agentId: "support-agent" });
return (
<div>
<h3>Support Agent Suggestions</h3>
{suggestions.map((s, i) => (
<div key={i}>{s.title}</div>
))}
</div>
);
}
agentId is resolved in the following order of precedence: explicit agentId option, agentId from the nearest CopilotChatConfigurationProvider, then the default agent ID ("default").isLoading becomes true when a dynamic suggestion reload begins and returns to false when generation completes.useConfigureSuggestions -- Configure static or dynamic suggestions