React js onClick can't pass value to method

后端 未结 30 2127
北荒
北荒 2020-11-22 07:05

I want to read the onClick event value properties. But when I click on it, I see something like this on the console:

SyntheticMouseEvent {dispatchConfig: Ob         


        
30条回答
  •  萌比男神i
    2020-11-22 07:38

    There are 3 ways to handle this :-

    1. Bind the method in constructor as :-

      export class HeaderRows extends Component {
         constructor() {
             super();
             this.handleSort = this.handleSort.bind(this);
         }
      }
      
    2. Use the arrow function while creating it as :-

      handleSort = () => {
          // some text here
      }
      
    3. Third way is this :-

       that.handleSort} >{column}
      

提交回复
热议问题