The return binding onClick in const in react indicates that the method cannot be found.

the binding event in a const return indicates that the method cannot be found, and the method has been written in the constructor. There is a loop in return.

  
        CardClick(){
                alert(0)
        }
       
        const list = this.state.data.map(function (m) {
          return <Card className="card-sence UserCardStyle" onClick={this.CardClick}></Card>
        });
    
    

onClick={alert(0)}alert

tried to bind this, with bind, but it didn"t work

Mar.05,2021

my friend, you have too much useless code. I'll give you some advice

  1. most importantly, your misinformation method CardClick is not posted
  2. there is too much useless code. You create a codepen or jsfiddle to make it easy for people who help you to read
  3. .
  4. your description needs to be clicked on again. I suggest you take a look at the wisdom of asking questions
  5. when you encounter this kind of baffling and non-logical code, I suggest you either find the problem bit by bit from the starting point of the trigger event. Either comment out half of the code that you think might be wrong, and if there is something wrong, it's not in that half, uncomment this half, comment out the other half, and repeat until you locate the source of the problem.

try onClick= {this.CardClick.bind (this)}


there is no this bound.


No this, is bound. Besides bind (this), you can also try the arrow function in ES6

CardClick=()=>{
    alert(0)
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ec9ae5-2f6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ec9ae5-2f6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?