import { useEffect, useState } from "react"; import { Divider, Space, Typography } from "antd"; import { TagOutlined } from "@ant-design/icons"; import ChapterFilter from "./ChapterFilter"; import ChapterList from "./ChapterList"; import ChapterTag from "./ChapterTag"; import ChapterAppendTag from "./ChapterAppendTag"; const { Title } = Typography; interface IWidget { studioName?: string; channelId?: string; tag?: string[]; } const CommunityChapterWidget = ({ studioName, tag = [] }: IWidget) => { const [tags, setTags] = useState(tag); const [searchKey, setSearchKey] = useState(); const [progress, setProgress] = useState(0.9); const [lang, setLang] = useState("zh"); const [type, setType] = useState("translation"); useEffect(() => { setTags(tag); }, [tag]); return ( <> setProgress(parseFloat(value))} onLangChange={setLang} onTypeChange={setType} /> <Space wrap> <TagOutlined /> {tags.map((item) => ( <ChapterTag key={item} // ✅ v6 推荐稳定 key data={{ key: item, title: item, }} closable onTagClose={() => { setTags((prev) => prev.filter((x) => x !== item)); // ✅ 避免闭包旧值 }} /> ))} <ChapterAppendTag tags={tags} progress={progress} lang={lang} type={type} onTagClick={(tag: string) => { setTags((prev) => (prev.includes(tag) ? prev : [...prev, tag])); }} /> </Space> { setTags([tag]); }} /> ); }; export default CommunityChapterWidget;