React js onClick can't pass value to method

后端 未结 30 2137
北荒
北荒 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条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:29

    1. You just have to use an arrow function in the Onclick event like this: 
    
     that.handleSort(theValue)} >{column}
    
    2.Then bind this in the constructor method:
        this.handleSort = this.handleSort.bind(this);
    
    3.And finally get the value in the function:
      handleSort(theValue){
         console.log(theValue);
    }
    

提交回复
热议问题