I am using React bootstrap table in my application. I have a button in each rows. However table is working fine but when I click on button , I am getting below error. uncaught typeerror: _this.handleclick is not a function at onclick. this.handleclick()}>Show handleclick() { alert("Click"); } Note: I am using formatter in the column to create a button inside bootstrap table
Loading

Tuhin PaulPosted Mar 18, 2023, 1:02 PM
You can use an arrow function to automatically bind
thisto the function, which can be more concise and easier to read.This will automatically bind
thisto the handleclick() function when the button is clicked.Tuhin PaulPosted Mar 18, 2023, 1:01 PM
you can define the handleclick() function like this:
And then bind this to the function in the constructor of the component:
Tuhin PaulPosted Mar 18, 2023, 1:00 PM
The error message "uncaught typeerror: _this.handleclick is not a function at onclick" typically occurs when the handleclick() function is not properly defined or bound to the correct this context. In other words, when the button is clicked, the function is not being executed because it cannot be found or accessed.
Check the scope where handleclick() is defined. Make sure it is within the same class or component where the button is rendered. If the function is defined in a different scope or component, it may not be accessible to the button. Bind this to handleclick() function. You can use the bind() method to bind this to the handleclick() function, which ensures that the function is called with the correct context.
Manikandan MurugesanPosted Mar 18, 2023, 5:39 AM
The error "uncaught typeerror: _this.handleclick is not a function at onclick" indicates that the function
handleclick()is not defined in the current scope where it is being called.Based on the code snippet you provided, it seems that the
handleclick()function is not properly defined or bound to the correctthiscontext.Here are some things you can try:
Check the scope where
handleclick()is defined. Make sure it is within the same class or component where the button is rendered.Bind
thistohandleclick()function. You can use thebind()method to bindthisto thehandleclick()functionthisautomatically. You can use an arrow function to automatically bindthisto the function.Shivangi RajdePosted Mar 17, 2023, 10:13 AM
Did you bind your function "handleclick()" so that it can be called?