是否可以在Link的state属性中传递一个函数,并更改在Link组件的path属性中传递的子组件中相同的状态。
我试图将父状态数组传递给子组件,但是如果我单击“链接”并返回到父组件,状态将重置。
<div className="cardContainer col-9 mx-2 col-md-6 col-lg-3
my-3" >
<div className="card-body text-center">
<Link to={
{
pathname: "/Details",
state: {
title: image.title,
path: image.path,
details: image.details,
price: image.price,
isInCart: image.isInCart,
// cart: { WANT TO PASS STATE
//HERE
// A HANDLER FUNCTION
//THAT WILL ADD TO CART
},
name: image.name
}
}
}>
<img className="image" key=
{image.name} src={image.path}
alt='T-shirt'/>
</Link>
{console.log(image.isInCart)}
</div>
不会重置的数组状态