Skip to content
Advertisement

Old state is being shown despite updating in React Highcharts click event

I want the new state to show, but I get different behavior. I have three points (look at code below or sketch) and if I click a point, then whatever state value is at that time, in future clicks the old value is shown. I am not sure what this is being caused by.

For example: Click point A, then 0 is printed. Increment state, then click A, still 0 is printed. Click point B, 1 is printed. Click point A, still 0 is printed.

Sketch: https://stackblitz.com/edit/react-bwskb9?file=index.js

JavaScript

Advertisement

Answer

Apparently, this is not something that is a problem in HighchartJS, but React hooks in particular. I solved this by using refs.

Refer here: How To Solve The React Hook Closure Issue?

Advertisement