I have a callback function from a table object where I was debugging some data and wanted to console.log the table object before it was updated with this.setState(). Now, I know this.setState is async, but I still expected to see the pre-update log, but instead it showed up post-update.
Here's the callback function:
onCellChange = (tableId, rowIdx, cellIdx) => e => {
const value = parseFloat(e.target.value);
console.log("TableID:", tableId);
console.log(tableData); //This prints the tableData object post-this.setState()
const tableTuple = { rowIdx, cellIdx, value, tableData, tableId };
this.setState({
tableData: updateInput(tableTuple)
});
};
To test this, I commented out the this.setState call and tried again and the console.log() would print the pre-update value as expected since it's not going into the updateInput method anymore. It makes sense, but then I am not sure how to get the pre-update console.log value.