Eugene Podoliako Eugene Podoliako - 11 months ago 62
React JSX Question

React transfer event into onClick

I have onClick event that excute fuction with several params. How to add to this paramt current event? I want to do in function somethig like this


My code has the following view (all not nesseccary code was removed):

import React from 'react';

export default class AllCarWashTable extends React.Component{

constructor(props) {
this.removeCarWashHandler = this.removeCarWashHandler.bind(this);

removeCarWashHandler(e, name, id){

generateRows() {
const removeCarWashHandler = this.removeCarWashHandler

return {
var cells = {
<button type="button"
onClick={()=> removeCarWashHandler(item['name'], item['id'])}>


Currenly my code leads to exception:
TypeError: Cannot read property 'stopPropagation' of undefined

How to fix this?

Answer Source

You forgot to pass the event to the function, it can be done giving the onClick event to the removeCarWashHandler function:

onClick={e => removeCarWashHandler(e, item['name'], item['id'])}