question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onClick in dataFormat() fires without actual 'clicking'

See original GitHub issue

I define my TableHeaderColumn as follows:

<TableHeaderColumn dataField="someData" dataFormat={this.valueFormatter}>Value</TableHeaderColumn>

As the valueFormatter I have following code:

valueFormatter(cell, row){
  return (
    <p onClick={console.log('value clicked')}>{cell}</p>
    );
}

The table generates without errors but in the console I see value clicked 10x (as much as there are rows). What I want: The function (in the above example a simple console.log()) should be called only if I click on the element.

What is wrong with my code, or is there another way to solve this?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AllenFangcommented, Nov 5, 2015

This should be good for your case,

class ValueFormatter extends React.Component{

  handleClick(e){
    console.log('value clicked');
  }

  render(){
    return (
      <p onClick={this.handleClick.bind(this)}>{this.props.data}</p>
    );
  }
};

function valueFormatter(cell, row){
  return (
    <ValueFormatter data={cell}/>
  );
}
1reaction
staminaloopscommented, Nov 5, 2015

Hello, Try

valueFormatter(cell, row){
  return (
    <p onClick={() => console.log('value clicked')}>{cell}</p>
    );
}

It worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

on("click", event) firing without clicking - javascript
Im trying to use jQuery's on("click") to fire a function that simply changes the class of the id which was clicked. But the...
Read more >
chart.events.click | highcharts API Reference
Fires when clicking on the plot background. One parameter, event , is passed to the function, containing common event information. Information on the...
Read more >
Element: click event - Web APIs | MDN
click fires after both the mousedown and mouseup events have fired, ... Returns true if the alt key was down when the mouse...
Read more >
JavaScript onclick event - javatpoint
The onclick event generally occurs when the user clicks on an element. It allows the programmer to execute a JavaScript's function when an...
Read more >
lightning-input - documentation - Salesforce Developers
This event has no default behavior that can be canceled. You can't call preventDefault() on this event. composed, true, This event propagates outside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found