我试图切换常见问题按钮,基本上当button 1被点击-> state 1被打开为真(工具提示打开)-> button 2被点击-> state 2为真,state 1被打开为假,工具提示关闭。这是我目前拥有的
const App = () => {
const [isOpen, setIsOpen] = useState(false);
const faqTipBtns = ['faqBtn1', 'faqBtn2', 'faqBtn3'];
const FaqtipIcon = (id) => {
return(
<button id = {id}
onClick = {() => toggleFaqTipBtn()}>
<FaqtipIcon isOpen = {isOpen}/>
</button>
)
};
const toggleFaqTipBtn = () => {
{faqTipBtns.map((id) => {
setIsOpen((prev) => !prev)
})}
return (
<form>
<RadioGroup>
<div>
<Radio
id='idA'
label = 'SomeLabel'/>
{FaqtipIcon('idA')}
</div>
{isOpen && (
<div>
<FaqtipContent
isOpen = {isOpen}
content = {<p>Some Content</p>}
/>
</div>
</RadioGroup>
</form>
)
}
2条答案
按热度按时间64jmpszr1#
这是你要找的按钮吗?
ghhkc1vu2#
React useState动态切换多个按钮
我理解你的问题,就像显示按钮相关的工具提示一样。example