Answer the question
In order to leave comments, you need to log in
How to correctly pass a function that sends a request to the button of a child component?
Good day to all!
Please tell me, I have a component (let's say - Parent), in which I render the card component using the map method. In the parent, I have a "deleteCard" function that sends a request to the server. How to properly pass this function to the button of each card?
const Test = () => {
const [test, setTest] = useState([])
const deleteCard = async (id) => {
try {
await deletedCard(id)
} catch (e) {
console.log('test')
}
}
return (
<div>
<Box sx={{ flexWrap: 'wrap', display: "flex", p: 1, m: 1 }}>
{
test.map(tes =>
<CardItem key={tes._id}
user={tes.user}
airdropName={tes.name}
link={tes.link}
notes={tes.notes}
date={tes.date}
/>
)
}
</Box>
</div>
);
};
export default Test;
<Typography variant="body2" color="text.secondary" component="span">
<div className={classes.bottom}>
<a href={props.link} target="_blank">
<IconButton color="primary" aria-label="link ref" component="span">
<PaidIcon />
</IconButton>
</a>
<IconButton color="error" aria-label="delete card" component="span"
onClick={???}>
<DeleteOutlineIcon />
</IconButton>
</div>
</Typography>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question