'use client'; import { motion } from 'framer-motion'; import { memo } from 'react'; import type { UseChatHelpers } from '@ai-sdk/react'; import type { VisibilityType } from './visibility-selector'; import type { ChatMessage } from '@/lib/types'; import { Suggestion } from './elements/suggestion'; interface SuggestedActionsProps { chatId: string; sendMessage: UseChatHelpers['sendMessage']; selectedVisibilityType: VisibilityType; } function PureSuggestedActions({ chatId, sendMessage, selectedVisibilityType, }: SuggestedActionsProps) { const suggestedActions = [ 'What are the advantages of using Next.js?', 'Write code to demonstrate Dijkstra\'s algorithm', 'Help me write an essay about Silicon Valley', 'What is the weather in San Francisco?', ]; return (
{suggestedActions.map((suggestedAction, index) => ( { window.history.replaceState({}, '', `/chat/${chatId}`); sendMessage({ role: 'user', parts: [{ type: 'text', text: suggestion }], }); }} className="text-left w-full h-auto whitespace-normal p-3" > {suggestedAction} ))}
); } export const SuggestedActions = memo( PureSuggestedActions, (prevProps, nextProps) => { if (prevProps.chatId !== nextProps.chatId) return false; if (prevProps.selectedVisibilityType !== nextProps.selectedVisibilityType) return false; return true; }, );