Home > Back-end >  how can i pass event and parameter onHandle change
how can i pass event and parameter onHandle change

Time:07-05

    const onCheckedValue = (notification, event) => {
        console.log('notification', notification);
        console.log('event', event);

        
    };

// I want to pass the event and another parameter to the above function how can I achieve that?

<Checkbox
 checked={notification.is_selected}
 onChange={onCheckedValue(notification,event)}
 value={notification}
/>
                                               

CodePudding user response:

The easiest way would be to use an anonymous function:

<Checkbox onChange={(event)=>onCheckedValue(notification, event)} />

Your version doesn't work because you call the function onCheckedValue during render, which means that the you're setting the return value of oncheckedValue to the prop onChange instead of the function itself.

CodePudding user response:

You are do that by wrapping the current onCheckedValue function call with a call back function and pass the values to the function from the state.

Get the values and feed them to this function

onChange={() => onCheckedValue(notification,event)}

  • Related