xgeek652
xgeek652

Reputation: 365

React Table - access state values inside Cell functions

I have multiple React-Table columns using the Cell functions :

In the main class :

Cell: function (props) {
  return (
    <span>
      <ChildClass
        id={props.original._id} myemail={this.state.email}
      />
    </span>
  );
},

So I get the error : TypeError: Cannot read property 'state' of undefined

I want to use the state inside that Cell function.

Thank you

Upvotes: 1

Views: 1265

Answers (1)

abhishek gupta
abhishek gupta

Reputation: 80

The function is not getting "this", You have to make this a lambda(arrow) function or need to bind the this.

Cell:(props) => {
  return (
    <span>
      <ChildClass
        id={props.original._id} myemail={this.state.email}
      />
    </span>
  );
},

I hope this will work for you, or otherwise share more details of the code.

Upvotes: 1

Related Questions