import { useEffect, useMemo, useState } from "react" import { useMessageStore } from "./messageStore" import { useTranslation } from "react-i18next" // 引导词推荐 export default function GuideQuestions({ locked, chatId, questions, onClick }) { const [showGuideQuestion, setShowGuideQuestion] = useMessageStore(state => [state.showGuideQuestion, state.setShowGuideQuestion]) const { t } = useTranslation() useEffect(() => { questions.length && setShowGuideQuestion(true) }, [chatId]) const words = useMemo(() => { if (questions.length < 4) return questions // 随机按序取三个 const res = [] const randomIndex = Math.floor(Math.random() * questions.length) for (let i = 0; i < 3; i++) { const item = questions[(randomIndex + i) % (questions.length - 1)] res.push(item) } return res }, [questions]) if (locked || !words.length) return null if (showGuideQuestion) return

推荐问题

{ words.map((question, index) => (
{ setShowGuideQuestion(false) onClick(question) }} >{question}
)) }
return null };