Skip to content

Image Mapper callbacks unable to access updated state - only access initialized state values #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ashahjahan opened this issue Feb 17, 2025 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed question A valid question

Comments

@ashahjahan
Copy link

Steps to reproduce

Steps:

  1. Code Sandbox: https://codesandbox.io/p/sandbox/nice-swanson-89lm88?file=%2Fsrc%2FApp.tsx%3A66%2C16
  2. Click on Floor area in Image Map
  3. State updates (check by clicking button), but the alert which access the same state variable "region" does not update in the ImageMapper call back and continues to stay "Initial State".

I have also found another similar error reported by a user here: https://stackoverflow.com/questions/72079850/trouble-setting-state-with-onclick-function-only-with-imagemapper-component-rea

For some reason your Image Mapper callbacks only accesses the initial state value even after the state value has been updated.

Current behavior

For some reason your Image Mapper callbacks only accesses the initial state value even after the state value has been updated.

Expected behavior

Image Mapper callbacks should access the current state values.

Context

No response

Error stack

No response

Live example link

https://codesandbox.io/p/sandbox/nice-swanson-89lm88?file=%2Fsrc%2FApp.tsx%3A66%2C16

Your environment

Desktop

  • OS: Mac
  • Browser: Firefox + Chrome
@ashahjahan ashahjahan added bug Something isn't working help wanted Extra attention is needed question A valid question labels Feb 17, 2025
@NishargShah
Copy link
Member

I didn't understand the question but I looked into the code and I found that the button does not have a callback so I resolved that issue after that I checked the code and functionality, and whenever I clicked on the floor, it updated the value.

change <button onClick={alert(region)}>Default Button</button> to <button onClick={() => alert(region)}>Default Button</button>

Here is the updated Codesandbox: https://codesandbox.io/p/sandbox/autumn-feather-gcmytw?file=%2Fsrc%2FApp.tsx%3A69%2C30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed question A valid question
Projects
None yet
Development

No branches or pull requests

2 participants