kriver kriver - 3 months ago 11
React JSX Question

Using onClick in react-virtulized Grid cell/row

I'm using the

Grid
component from
react-virulized
and need to handle click event at a column cell and row level.
I tried adding an onClick to the
div
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)}/>
</div>
)
}


Thanks!

Answer

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
Comments