React Antd Table 数据渲染按钮触发onClick事件解决办法

发布时间 2023-12-21 10:55:53作者: Chaplink

react在渲染时会触发table里面的rander函数下的onClick方法 我的onClick是触发Modal 弹窗 且close后还是会一直触发Modal弹窗
初始代码如下

 {
            title: '操作',
            key: 'operation',
            fixed: 'right',
            width: 100,
            render: (item) => <Button type="link" onClick={showModal(item)}>编辑</Button>,
        }

解决办法:在onClick中修改为箭头函数

{
            title: '操作',
            key: 'operation',
            fixed: 'right',
            width: 100,
            render: (item) => <Button type="link" onClick={()=>showModal(item)}>编辑</Button>,
        },