react-spreadsheet
react-spreadsheet copied to clipboard
onCellCommit() prop causing prevCell to be null on first trigger
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>
)
}
Thank you @burnedfaceless for the detailed report.