Home > Software engineering >  How to get ref value of button in function [react]
How to get ref value of button in function [react]

Time:06-10

I have a simple buttons:

<button ref={btnRef1} onClick={loader} ></button>
<button ref={btnRef2} onClick={loader} ></button>

In function I want to get the value of clicked button:

const loader = (e) => {
console.log(e.target.ref); // does not work
};

How can I get ref value of clicked button? Below short explain my problem:

Input: [button1] <-click
Output: "btnRef1"

CodePudding user response:

You can see event object via console.log(e):

then analyze object to see which method will help you

const loader = (e) => {
console.log(e); // does not work
};

  • Related