react-spreadsheet icon indicating copy to clipboard operation
react-spreadsheet copied to clipboard

onCellCommit() prop causing prevCell to be null on first trigger

Open burnedfaceless opened this issue 2 years ago • 1 comments

When calling the onCellCommit() prop I am encountering an issue where the value of prevCell is null the first time onCellCommit() is triggered. On subsequent firings it works correctly. Here is my code and the output of my JavaScript console.

// changing 'Vanilla' in cell to 'Vanilla Ice Cream' and pressing enter.
prevCell:  null
nextCell:  {value: 'Vanilla Ice Cream'}
lastChanged:  {row: 0, column: 0}

// changing 'Strawberry' to 'Strawberry Ice Cream'
prevCell:  {value: 'Strawberry'}
nextCell:  {value: 'Strawberry Ice Cream'}
lastChanged:  {row: 1, column: 0}

// changing 'Chocolate' to 'Chocolate Chip Cookies'
prevCell:  {value: 'Chocolate'}
nextCell:  {value: 'Chocolate Chip Cookies'}
lastChanged:  {row: 0, column: 1}
const App = () => {

  const onCellCommit = (prevCell, nextCell, lastChanged) => {
    console.log('prevCell: ', prevCell)
    console.log('nextCell: ', nextCell)
    console.log('lastChanged: ', lastChanged)
  }

  const data = [
    [{ value: "Vanilla" }, { value: "Chocolate" }],
    [{ value: "Strawberry" }, { value: "Cookies" }],
  ]
  
  return (
    <div>
      <Spreadsheet
        onCellCommit={onCellCommit}
        data={data}
      />
    </div>
  )
}

burnedfaceless avatar Dec 28 '22 23:12 burnedfaceless

Thank you @burnedfaceless for the detailed report.

iddan avatar Dec 30 '22 14:12 iddan