showcase/shell-docs/src/content/reference/react-native/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-native";
function useSuggestions(options?: UseSuggestionsOptions): UseSuggestionsResult;
import { Text, View } from "react-native";
function SuggestionsList() {
const { suggestions, isLoading } = useSuggestions();
if (isLoading) {
return <Text>Loading suggestions...</Text>;
}
return (
<View>
{suggestions.map((suggestion, i) => (
<View key={i}>
<Text style={{ fontWeight: "bold" }}>{suggestion.title}</Text>
<Text>{suggestion.message}</Text>
</View>
))}
</View>
);
}
import { Text, TouchableOpacity, View } from "react-native";
function SuggestionsPanel() {
const { suggestions, reloadSuggestions, clearSuggestions, isLoading } =
useSuggestions();
return (
<View>
<View>
<TouchableOpacity onPress={reloadSuggestions} disabled={isLoading}>
<Text>Refresh</Text>
</TouchableOpacity>
<TouchableOpacity onPress={clearSuggestions}>
<Text>Clear</Text>
</TouchableOpacity>
</View>
{suggestions.map((suggestion, i) => (
<TouchableOpacity key={i} disabled={suggestion.isLoading}>
<Text>{suggestion.title}</Text>
</TouchableOpacity>
))}
</View>
);
}
import { Text, View } from "react-native";
function AgentSuggestions() {
const { suggestions } = useSuggestions({ agentId: "support-agent" });
return (
<View>
<Text>Support Agent Suggestions</Text>
{suggestions.map((s, i) => (
<Text key={i}>{s.title}</Text>
))}
</View>
);
}
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