0

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!

kriver
  • 1,588
  • 3
  • 20
  • 33

1 Answers1

1

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
Igorsvee
  • 4,101
  • 1
  • 25
  • 21