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

use onBeforeUnmount in useEventListener #2356

Merged
merged 1 commit into from May 15, 2023

Conversation

bnabriss
Copy link
Contributor

@bnabriss bnabriss commented May 5, 2023

use onBeforeUnmount in useEventListener instead of onUnmounted since onUnmounted will not work if you trying to pass some element ref from the consumer component. Using the onUnmounted the ref will be null since the component is unmounted, so we should use onBeforeUnmount

Description of Problem

using will throw an error:

Cannot read properties of null (reading 'removeEventListener')

if you use Element ref

Proposed Solution

Use onBeforeUnmount, no remove the listener just before destroying the component

use `onBeforeUnmount` in `useEventListener` instead of `onUnmounted` since `onUnmounted will not work if you trying to pass some element ref from the consumer component.
Using the  `onUnmounted` the ref will be null since the component is unmounted, so we should use `onBeforeUnmount`
@netlify
Copy link

netlify bot commented May 5, 2023

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 0d74d7e
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/64558ae0bf43c400085db033
😎 Deploy Preview https://deploy-preview-2356--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

@NataliaTepluhina NataliaTepluhina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnabriss thank you, that's a good point!

@NataliaTepluhina NataliaTepluhina merged commit 30cb9d9 into vuejs:main May 15, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants