kriver kriver - 11 months ago 59
React JSX Question

Using onClick in react-virtulized Grid cell/row

I'm using the

component from
and need to handle click event at a column cell and row level.
I tried adding an onClick to the
returned by my cellRenderer method, but it don't appear to work. Has anyone got this working? See below:

_renderCell ({ columnIndex, rowIndex }) {
// name = getFrom(columnIndex, rowIndex)
return (
<div className={'cell'} >
<input type="text" {name} maxLength={2} onClick={alert(columnIndex)}/>


Answer Source

Currently you invoke the function instead of referencing it, so when the DOM is loaded, the alert gets called.To make your code work use the bind method:

alert.bind(null,columnIndex); // alert will always have columnIndex's value as the first argument