-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: React overlay hooks (useIon*) are not fully memorised #23741
Comments
Hey @FWeinb, thanks for the issue and the useful code reproduction! I agree that this is unwanted behavior and I think your proposed solution is in the right direction. If you could create a PR for this, that would be very helpful. 😄 |
Closing this because I submitted a PR fixing this. |
Thanks for the PR! I am going to keep this issue open until the PR gets merged. |
…24010) resolves #23741 Co-authored-by: Fabrice <[email protected]>
Thanks for the contribution on this issue @FWeinb! The fix for this issue has been merged and will be available in the next release of Ionic Framework. |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prequisites
Ionic Framework Version
Current Behavior
Using the new overlay hooks feels great and is a nice improvement in my opinion. When using them I noticed that for
useIon{Toast|Alert|Popover|...}
the results aren't memorised and change each render. This will cause a great deal of overhead when thepresent
/dismiss
methods will be dependencies of otheruseEffects
.You can see a demo of this behaviour here
Expected Behavior
All the
useIon*
hooks should memorised the returnedpresent
/dismiss
to match developers expectation.Steps to Reproduce
useIonToast
React.useEffect(..., [presentToast])
Code Reproduction URL
https://codesandbox.io/s/ionic-hooks-memorisation-5o4yc?file=/src/App.tsx
Ionic Info
No response
Additional Information
I tracked this issue down to
useController
. Adding someReact.useCallback
hereionic-framework/packages/react/src/hooks/useController.ts
Line 38 in 7315e01
and here
ionic-framework/packages/react/src/hooks/useController.ts
Line 74 in 7315e01
and a
React.useMemo
ionic-framework/packages/react/src/hooks/useController.ts
Lines 79 to 82 in 7315e01
will ensure that the
controller
is memorised. Looking at the otheruseIon*
hooks should be straight forward. FixinguseIonToast
would need aReact.useCallback
hereionic-framework/packages/react/src/hooks/useIonToast.ts
Line 18 in 7315e01
If you think this is something that should be implemented I can create a PR for these changes.
The text was updated successfully, but these errors were encountered: