S
SolidJS2y ago
Max

Using lifecycle functions in abstract function?

Just wondering if there are any consideration to be taken into account when calling lifecycle functions like onMount or onCleanup inside some abstracted function made to reuse code, like a hook in react. Would it work fine so long as the function gets called in a component, or anything else to keep in mind? And is this something inline with what custom directives like use are designed for, or its unrelated? For context in my specific situation would like to register global event listeners for mouseup and remove them once the component is gone. Thank you for any input!
2 Replies
deluksic
deluksic2y ago
it will work as long as there's an owner of that scope. See getOwner and runWithOwner. examples of where it wouldn't work: async, event handlers, setTimeout etc.
Max
MaxOP2y ago
nice thank you
Want results from more Discord servers?
Add your server