'React table tanstack - Confirm before expanding row

I have a React table which allows expanding one row at a time. However, I allow editing the expanded row data, hence I want to popup a modal before expanding the second row asking whether to expand it based on whether the user edited the row. If user clicks yes, I would collapse the previous row and expand this one else would not expand the new one keeping the previous row expanded.

I'm struggling to find where should I call the function to show the modal/confirmation box and check for the user confirmation on click of the next row, before the row is expanded.

Or is there any other efficient way to approach this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source