you need to do this:
categories.map((category, index) => {
const location = {
pathname: `/categories/edit/`,
state: {
category,
},
};
return (
<tr key={index}>
<th scope="row">{index}</th>
<td>{category.name}</td>
<td>50</td>
<td>
<Link
to={location}
>
Edit
</Link>
</td>
<td>
<Button
variant={"danger"}
onClick={deleteCategoryHandler}
data-id={category._id}
>
Delete
</Button>
</td>
</tr>
);
});
and in the destination component
just use something like this to get location
object and then its state
property:
const location = useLocation();
const category = location?.state?.category;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…