我有一个映射的项目的手风琴,每个项目都有一个Favourite
-图标。单击该图标后,它需要更改颜色(已经这样做了)并将{name.toUpperCase()}
的{{1}}属性传递到BadgeButton
页。有人可以解释/告诉我如何吗?任何帮助将不胜感激。
这是Favourites
页:
Accordion
export default function Accordion({ name, description, use, recipe, liked }) {
const [clicked, setClicked] = useState(false);
function handleClick() {
setClicked(!clicked);
}
return (
<AccordionDiv>
<AccordionHead onClick={handleClick}>
<div>
<BadgeButton>{name.toUpperCase()}</BadgeButton>
<StyledArrow clicked={clicked} />
</div>
<div>{use}</div>
</AccordionHead>
<AccordionContent clicked={clicked}>
<span>{description}</span>
<p>{recipe}</p>
<StyledIcons>
<Favourite liked={liked} />
<Vote />
</StyledIcons>
</AccordionContent>
</AccordionDiv>
);
}
页:
Favourites
答案 0 :(得分:0)
您必须将状态设置为州,然后将其作为道具传递给收藏夹。像这样的东西:
const [nameClicked, setNameClicked] = useState("");
function handleClick() {
setClicked(!clicked);
setNameClicked(name);
}
<AccordionDiv>
...
<Favourite liked={liked} name={nameClicked} />
</AccordionDiv>