0

I'm trying to pass both arguments and event to an external function in React.

If I invoke it this way,

 cell={ function (e){
                return CellWithEditing(x,y,z)
              }

It cannot find "this" and says props of undefined. As this is an external function I cannot even bind this.

This code works without the event -

 <GridColumn
          title="Manage"
          width="190px"
          minResizableWidth={170}
          cell={ CellWithEditing(
              this.props.config.title,
              this.props.manageGrid.edit,
              this.props.manageGrid.remove,
              this.props.manageGrid.addUsers,
              this.props.permission
            );
          }
          sortable={false}
          filterCell={this.emptyCell}
        />

The function outside the default class being called -

function CellWithEditing(x, y, event) {
  return class extends GridCell {
    constructor(props) {
      super(props);
      this.core = this.props.args;
    }

    render() {
      return (
       <h1>Sample Data</h1>
      );
    }
  };
}

This code does not work, when I use arrow function -

 <GridColumn
          title="Manage"
          width="190px"
          minResizableWidth={170}
          cell={ 
              (e)=>{
              CellWithEditing(
              this.props.config.title,
              this.props.manageGrid.edit,
              e)
             }
        }
          sortable={false}
          filterCell={this.emptyCell}
     />

I expect the function to be returned along with the event data.

0 Answers0