【发布时间】:2022-09-27 23:35:33
【问题描述】:
所以我在调用我在道具中接收的 React 方法时遇到问题。
这是我的代码
render() {
const {
handleDeleteItem,
} = this.props;
return (
<Fragment>
<IconButton
onClick={() => handleDeleteItem(2)}>
<DeleteForeverIcon />
</IconButton>
</Fragment>
)};
但是当我这样使用它时它会起作用
onClick={handleDeleteItem(2)}
我正在使用类组件,我想要实现的主要目标是在该按钮单击时调用 2 个函数,例如一种方法来自道具,另一种方法是简单的(console.log 什么的)
-
你能把它扩展成一个可运行的minimal reproducible example 来演示这个问题吗?
标签: reactjs