Skip to content
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

GMap onOverlayDragEnd event callback has access to outdated react states #2714

Closed
InTheNooB opened this issue Mar 31, 2022 · 2 comments
Closed
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@InTheNooB
Copy link

InTheNooB commented Mar 31, 2022

I'm submitting a

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Codesandbox Case (Bug Reports)
https://codesandbox.io/s/primereact-test-forked-htby5q?file=/src/index.js
(Open the console and set filtering to "info")

Current behavior
When getting react states values inside the callback of the event onOverlayDragEnd, these values are outdated if the states have been modified AFTER the initialization of the <GMap> component. (the setters are working correctly, just the getters are broken)

Expected behavior
React states values are up to date.

Minimal reproduction of the problem with instructions

  1. Set a state (mystate) with a default value
  2. Load a <GMap> component and define a callback for the event onOverlayDragEnd
  3. Add an overlay to this map
  4. Update the state (mystate)
  5. Trigger the onOverlayDragEnd and log the value of the state (mystate) inside the callback of the event

Please tell us about your environment:
macOS Big Sur Version 11.6.2, VS Code, NPM

  • React version:
    17.0.2

  • PrimeReact version:
    7.2.1

  • Browser:
    all

  • Language:
    JSX

@melloware
Copy link
Member

@InTheNooB do you have a proposed fix?

@InTheNooB
Copy link
Author

InTheNooB commented Mar 31, 2022

@melloware

The workaround I found is to update a state in the event callback setOnOverlayDragEnd(event) (maybe I should mention it in my initial post but setters work fine) and add a React.useEffect() with this state as dependency and use this React.useEffect() to do what was supposed to be done in the event callback.

But I didn't find a way to fix this bug unfortunately

@mertsincan mertsincan self-assigned this Apr 11, 2022
@mertsincan mertsincan added the Type: Bug Issue contains a defect related to a specific component. label Apr 11, 2022
@mertsincan mertsincan added this to the 8.0.0-rc.2 milestone Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

3 participants