I am using vtkRenderWindowInteractor as an interactor with a onMiddleButtonPress defined at runtime. I’m trying to implement a feature that overwrites at one point the existing onMiddleButtonPress callback with a new one.
Defining the 2nd and new callback function this way leads to an unexpected behavior where both of them are triggered one after another:
renderWindow.getInteractor().onMiddleButtonPress( (calldata: any) => {
// code of the new callback function should do
})
There are bunch of undocumented methods in the documentation that might do what I am looking for
Initially, before initiating this post, I went for the first option, but for some reasons, it didn’t play well with React.useState hook (basically, updated state variable couldn’t be retrieved inside of the callback). I’m unsure if this problem is related to my project. I’ll try to create a minimal sandbox trying to replicate the problem I am having.
Getting back with the CodeSandbox demonstrating the unexpected behavior I am having.
Basically, what I am trying to do is to combine a pointPicker callback and react.useState. The idea to update the state depending on whether a point was picked or not.
Notice how the state gets updated correctly and triggers the useEffect, but this is not reflected when trying to access the state variable inside of the callback. Somehow, the default value is always returned