react-plotly.js
react-plotly.js copied to clipboard
Custom ModeBar Button click uses old state values
modeBarButtonsToAdd: [{ name: 'customDownload', title: 'Download', icon: Plotly.Icons.disk, click: (div) => {console.log(div); console.log(chartState); console.log(chartData); } }
chartState is the Plotly state variable passed to the Plot element (data, layout, frames, config) chartData is the raw data source that is used to generate the data traces for chartState chartData gets updated during app cycle which updates chartState All of the data outputs from click event are logged as point of init which has an empty data array, even the chart div that gets passed from the click function
I have the same issue.
My workaround is to use a react ref which I always update. In the click handler, we have access to the latest value with ref.current.