Let's talk about the issue of passing parameters to React onClick

Let's talk about the issue of passing parameters to React onClick

Background

In a list like the one below, clicking the Delete button requires the delete operation to be performed

List generation:

	{
		title: 'Operation',
		dataIndex: 'rowguid',
		key: 'rowguid',
	    render: (text, record) => (
		      <Space size="middle">
		        <Button type="primary" size="small" >Modify</Button>
		        <Button type="danger" size="small" >Delete</Button>
		      </Space>
			)
	}

I need to add an event when rendering and generating the delete button, and call it when it is clicked, and also pass parameters. This parameter

I started by writing:

But the problem is that the delByGuid function is executed when the page is loaded, and the output of our console is:

Not only that, when I clicked the delete button, the function was not executed. It seems that this is not allowed.

question:

1. Executed when the page is rendered

2. Click the button, onclick is not executed

Solution:

	{
		title: 'Operation',
		dataIndex: 'rowguid',
		key: 'rowguid',
	    render: (text, record) => (
		      <Space size="middle">
		        <Button type="primary" size="small" >Modify</Button>
		        <Button type="danger" size="small" onClick={(e)=>delByGuid(text)}>Delete</Button>
		      </Space>
			)
	}

onClick={(e)=>delByGuid(text)}

This solves the problem. It doesn't work when the page is loaded, but it can be called when it is clicked.

This is the end of this article about React onClick passing parameters. For more relevant React onClick passing parameters content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • React passes parameters in several ways
  • Parameter passing between react components (detailed explanation)

<<:  Implementation of docker-compose deployment project based on MySQL8

>>:  Detailed deployment steps for MySQL MHA high availability configuration and failover

Recommend

VMware Workstation Installation (Linux Kernel) Kylin Graphic Tutorial

This article shares with you how to install Kylin...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

Analysis of the principle of Nginx using Lua module to implement WAF

Table of contents 1. Background of WAF 2. What is...

Will mysql's in invalidate the index?

Will mysql's IN invalidate the index? Won'...

How to change the encoding of MySQL database to utf8mb4

The utf8mb4 encoding is a superset of the utf8 en...

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...

Detailed explanation of MySQL Truncate usage

Table of contents MySQL Truncate usage 1. Truncat...

HTML meta explained

Introduction The meta tag is an auxiliary tag in ...

Detailed explanation of the calculation method of flex-grow and flex-shrink in flex layout

Flex(彈性布局) in CSS can flexibly control the layout...

12 types of component communications in Vue2

Table of contents 1. props 2..sync 3.v-model 4.re...

How to use nginx to access local static resources on Linux server

1. Check whether port 80 is occupied. Generally, ...

How to use mysqladmin to get the current TPS and QPS of a MySQL instance

mysqladmin is an official mysql client program th...