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

The core process of nodejs processing tcp connection

A few days ago, I exchanged some knowledge about ...

Specific use of useRef in React

I believe that people who have experience with Re...

Database backup in docker environment (postgresql, mysql) example code

Table of contents posgresql backup/restore mysql ...

A brief discussion on the types of node.js middleware

Table of contents Overview 1. Application-level m...

Implementation of vite+vue3.0+ts+element-plus to quickly build a project

Table of contents vite function Use Environment B...

Various types of MySQL indexes

What is an index? An index is a data structure th...

Detailed explanation of Vue plugin

Summarize This article ends here. I hope it can b...

MYSQL Left Join optimization (10 seconds to 20 milliseconds)

Table of contents 【Function Background】 [Raw SQL]...

How to enable TLS and CA authentication in Docker

Table of contents 1. Generate a certificate 2. En...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...

How to modify the port mapping of a running Docker container

Preface When docker run creates and runs a contai...

Detailed explanation of creating, calling and managing MySQL stored procedures

Table of contents Introduction to stored procedur...

A brief discussion on the design of Tomcat multi-layer container

Table of contents Container Hierarchy The process...

Javascript tree menu (11 items)

1. dhtmlxTree dHTMLxTree is a feature-rich Tree M...