-
Notifications
You must be signed in to change notification settings - Fork 39
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
[IMP] components: use a hook to register/clean up event listeners #2469
Conversation
3cbb25f
to
b8e8a32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍
*/ | ||
|
||
export function useRefListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the additional line between the docstring and the function
...listener: Parameters<typeof addEventListener> | ||
) { | ||
useEffect( | ||
(el) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(el) => { | |
(el: HTMLElement | null) => { |
Currently, we register event listener on `Ref.el` upong mount and unmount steps of the component lifecycle. However, depending on the component structure, the element of the `Ref` could change from a rendering to another*, preventing the proper cleaing of the listener. This commit introduces a new hook to handle such cases more correctly. * an example can be found in component `SelectionInput`.
b8e8a32
to
6e35167
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
robodoo r+
Currently, we register event listener on `Ref.el` upong mount and unmount steps of the component lifecycle. However, depending on the component structure, the element of the `Ref` could change from a rendering to another*, preventing the proper cleaing of the listener. This commit introduces a new hook to handle such cases more correctly. * an example can be found in component `SelectionInput`. closes #2469 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Currently, we register event listener on
Ref.el
upong mount and unmount steps of the component lifecycle.However, depending on the component structure, the element of the
Ref
could change from a rendering to another*, preventing the proper cleaing of the listener.This commit introduces a new hook to handle such cases more correctly.
SelectionInput
.Description:
description of this task, what is implemented and why it is implemented that way.
Odoo task ID : TASK_ID
review checklist