[RFC] Returning onUnmounted within onMounted #593
Replies: 7 comments 9 replies
-
What's the motivation? Accessing state inside onMounted(() => {
console.log('onMounted')
onUnmounted(() => {
console.log('onUnmounted')
})
}) If it works, what's the benefit of returning a function? And in both cases... I wonder: if a component is recycled (unmounted from DOM, then mounted again), both approaches would create multiple |
Beta Was this translation helpful? Give feedback.
-
This method is functionally consistent with |
Beta Was this translation helpful? Give feedback.
-
I feel this adds another way to do things without much gain. I can't just see if I've attached an If I only want to listen for unmount, then I must use a dedicated hook. And I agree with @jods4 about the timing: if a component is unmounted and mounted again, is a new unmount callback registered? What do you do with the existing one? |
Beta Was this translation helpful? Give feedback.
-
I understand the OP's point is that returning an
|
Beta Was this translation helpful? Give feedback.
-
I feel like this will just make Vue harder to learn and vue apps harder to maintain, because there will be 2 ways of doing the same thing. If there is nothing to gain from it, I would avoid increasing the complexity of the framework. |
Beta Was this translation helpful? Give feedback.
-
I think explicitly calling If we don't want to explicitly import onMounted((onUnmounted) => {
console.log("mounted")
onUnmounted(() => {
console.log("unmounted")
})
}) I'd rather imported |
Beta Was this translation helpful? Give feedback.
-
Temporarily close this RFC. If someone has passed a function with a return value to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Expecting to return a function in onMounted that will be called in onUnmounted.
PR
expected:
Beta Was this translation helpful? Give feedback.
All reactions