showcase/shell-docs/src/content/reference/react-native/hooks/useThreads.mdx
useThreads is a React hook for managing conversation threads on the Enterprise Intelligence Platform. It fetches the thread list for a given agent, keeps it synchronized in realtime via WebSocket, and exposes mutation methods for renaming, archiving, and deleting threads.
Threads are sorted by most recently updated first. The hook supports cursor-based pagination when a limit is provided.
import { useThreads } from "@copilotkit/react-native";
function useThreads(input: UseThreadsInput): UseThreadsResult
import { useThreads } from "@copilotkit/react-native"; // [!code highlight]
import { FlatList, Text, TouchableOpacity, View } from "react-native";
function ThreadList() {
const {
threads,
isLoading,
renameThread,
archiveThread,
deleteThread,
} = useThreads({ agentId: "my-agent" }); // [!code highlight]
if (isLoading) {
return (
<View>
<Text>Loading threads...</Text>
</View>
);
}
return (
<FlatList
data={threads}
keyExtractor={(thread) => thread.id}
renderItem={({ item: thread }) => (
<View>
<Text>{thread.name ?? "Untitled"}</Text>
<TouchableOpacity onPress={() => renameThread(thread.id, "New name")}>
<Text>Rename</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => archiveThread(thread.id)}>
<Text>Archive</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => deleteThread(thread.id)}>
<Text>Delete</Text>
</TouchableOpacity>
</View>
)}
/>
);
}
error state updates with the most recent error from any operation.threads array stays sorted by updatedAt descending (most recent first).generateThreadNames on the runtime.useThreads, the web useThreads this hook mirrors