https://codepen.io/vdgodse/pen/ExmjGLN
In plotly we can provide config as: modeBarButtonsToAdd: [
{
name: 'button1',
icon: Plotly.Icons.pencil,
direction: 'up',
click: function(gd) {
// this does not update on rerender and always holds the stale react state in closure as shown in the codepen demo
}
}],
Click on the pencil icon to see alert with realCount and staleCount. Since second click the counts diverge.