-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Popover onClose runs in the loop after closing the popover #7115
Comments
In my example in codesandbox, you even can press the Count button, when the popover is closed. That would run in the loop an Screen.Recording.2024-11-12.at.15.48.51.mov |
In your example, the So it will be called in a loop. // use-popover.ts
useDidUpdate(() => {
if (!_opened) {
options.onClose?.();
} else {
options.onOpen?.();
}
}, [_opened, options.onClose, options.onOpen]); Cache the callbacks <Popover
onClose={useCallback(() => { setCount((c) => c+1); }, [])}
onOpen={useCallback(() => {}, [])}
/> |
My callback
I see that mantine run |
If you are talking about trigger logic, it might be so, it depends on the author. My choice is to manage the state within the current component as much as possible. If the callback function needs to use some state, I would use ref instead of modifying the callback function. |
Fixed in 7.14.1 |
Dependencies check up
What version of @mantine/* packages do you have in package.json?
7.13.4, 7.13.5
What package has an issue?
@mantine/core
What framework do you use?
create-react-app (CRA)
In which browsers you can reproduce the issue?
Chrome
Describe the bug
In case the
onClose
callback depends on some state value and then changes it, then, after first closing of the popover, on close callback runs in the loop.I attached a link to codesandbox. Just open and close popover and you will see how updates count. When I open Popover again, it stops counting. a
If possible, include a link to a codesandbox with a minimal reproduction
https://codesandbox.io/p/sandbox/mantine-popover-bug-forked-dst5wp?file=%2Fsrc%2FApp.tsx
Possible fix
In my opinion, somewhere in the code, you run onClose when the callback is updating because of some dependencies state update
Self-service
The text was updated successfully, but these errors were encountered: