[英]Passing properties in react.js / add to favourites
I have a mapped accordion of items, that each have a Favourite
-icon.我有一个映射的手风琴项目,每个项目都有一个
Favourite
图标。 Upon clicking that icon it needs to change color (already does that) and pass the {name.toUpperCase()}
property of the BadgeButton
to to the Favourites
-page.单击该图标后,它需要更改颜色(已经这样做了)并将 BadgeButton 的 {
BadgeButton
{name.toUpperCase()}
属性传递到Favourites
页面。 Can someone explain/show me how?有人可以解释/告诉我怎么做吗? Any help would be much appreciated.
任何帮助将非常感激。
This is the Accordion
-page:这是
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
-page: Favourites
-页面:
export default function Favourites() {
return (
<WrapperDiv>
<Header />
<Title headline>FAVOURITES</Title>
<BadgeButtonClose>{}</BadgeButtonClose>
</WrapperDiv>
);
}
You would have to set the name in state and pass it as a prop to Favourites.您必须在 state 中设置名称并将其作为道具传递给收藏夹。 somethiing like this:
像这样的东西:
const [nameClicked, setNameClicked] = useState("");
function handleClick() {
setClicked(!clicked);
setNameClicked(name);
}
<AccordionDiv>
...
<Favourite liked={liked} name={nameClicked} />
</AccordionDiv>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.