sizzlingseal
sizzlingseal

Reputation: 27

Unexpected use of 'event' getting value of an icon. (ReactJS)

I want to get the value of my icon but it says that event is deprecated.

const TaskContainer = (props) => {
function handleChange(event){ 
        alert(event.target.value);
    }

return (
 <i className='bx bx-add-to-queue bx-tada-hover' value={props.columnname.id} onClick={handleChange(event)} ></i>
)
}

Upvotes: 0

Views: 43

Answers (2)

I believe you need to write like this:

onClick={event => handleChange(event)}

Or that way:

onClick={handleChange}

Upvotes: 3

Anand Bhushan
Anand Bhushan

Reputation: 783

You're calling the function, instead you should do this-

<i className='bx bx-add-to-queue bx-tada-hover' value={props.columnname.id} onClick={handleChange} ></i>

or,

<i className='bx bx-add-to-queue bx-tada-hover' value={props.columnname.id} onClick={(event) => handleChange(event)} ></i>

Please have a look at handling events in react for better understanding of how event handlers should be put up in react.

Upvotes: 0

Related Questions