gpt4 book ai didi

reactjs - 箭头图标中的 react-bootstrap Accordion 问题

转载 作者:行者123 更新时间:2023-12-04 13:09:25 24 4
gpt4 key购买 nike

我正在对我的项目使用 react-bootstrap Accordion 。我正在尝试将向上和向下箭头按钮指示器添加到我的 Accordion 标题中。请检查问题的示例代码

  const [open, setOpen] = useState(false);

<Accordion.Toggle as={Button} variant="link" eventKey="2" className="according-text" onClick={() => setOpen(!open)}>
<i className="mdi mdi-view-headline"> </i> LINES {open ? <i className="mdi mdi-menu-down"></i> : <i className="mdi mdi-menu-up"></i>}
</Accordion.Toggle>
<Accordion.Toggle as={Button} variant="link" eventKey="2" className="according-text" onClick={() => setOpen(!open)}>
<i className="mdi mdi-view-headline"> </i> MATCH INVICE LINES{open ? <i className="mdi mdi-menu-down"></i> : <i className="mdi mdi-menu-up"></i>}
</Accordion.Toggle>

当我单击第一个 Accordion 标题时,第二个 Accordion 标题图标会更改。检查下图初始状态 enter image description here

点击第一个 Accordion 标题后 enter image description here

我如何防止这种情况。你能帮我解决这个问题吗?谢谢

最佳答案

状态应该是Accordion的数组索引,你可以看下面的代码,希望对你有帮助

 const [idx, setIdx] = useState([]);

{[...yourArray].map((accordion, index) => (
<Accordion.Toggle
as={Button}
variant="link"
eventKey="2"
className="according-text"
onClick={() => {
if (idx.includes(index)) setIdx(idx.filter(i => i !== index));
else setIdx([...idx, index]);
}}
>
<i className="mdi mdi-view-headline"> </i> LINES{" "}
{idx.includes(index) ? (
<i className="mdi mdi-menu-down"></i>
) : (
<i className="mdi mdi-menu-up"></i>
)}
</Accordion.Toggle>
))}

关于reactjs - 箭头图标中的 react-bootstrap Accordion 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67174485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com