-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Closed
Description
I really dont understand why getCurrentInstance
is descripted as anti pattern in application code.
Here is the documentation part that i mean:
docs/src/api/composition-api.md
Lines 216 to 223 in 10ed910
## `getCurrentInstance` | |
`getCurrentInstance` enables access to an internal component instance. | |
:::warning | |
`getCurrentInstance` is only exposed for advanced use cases, typically in libraries. Usage of `getCurrentInstance` is strongly discouraged in application code. Do **NOT** use it as an escape hatch to get the equivalent of `this` in Composition API. | |
::: | |
I am working on a large vue 2.6 codebase and in my optinion using getCurrentInstance
can be a great improvement for reusable hooks, which need SetupContext
. Currently we are passing the context, but in my option it makes refactoring hard and i think it would be a great improvment to use getCurrentInstance
in some cases.
Whats the reason its descripted as anti pattern?
SetupContext
Type doens't get extended?- Is it a perfomance problem?
For example a nested hook needs some vuetify variable of SetupContext
or use of a Router without Provide / Inject API
nf-cschirin
Metadata
Metadata
Assignees
Labels
No labels