-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Easier-to-use HOC method #5934
Comments
It's the same as React when using render functions: function HoC (Comp) {
return {
render (h) {
return h(Comp, { props: ... })
}
}
} Regardless this is fully implementable in userland and doesn't need to be part of core. |
@yyx990803 thanks. |
The annoying this about this is that the HoC must declare all the props of the wrapped components. There are two annoying things about this:
In react you just have |
@blocka there's already https://vuejs.org/v2/api/#vm-props |
@jkzing @yyx990803 Here is my contrived example: https://jsfiddle.net/4cc6mrs0/ As you can see, in order for In this example it's pretty simple: WrappedComponent.props. But once you're dealing with mixing HoC props, and WrappedComponent props, things get pretty hairy, for the reasons I've explained earlier. |
From peeking around, it seems all undeclared props hangout at |
Oh...sorry, I was wrong, it's not relevant with #5983...😅 |
What problem does this feature solve?
Currently I can't find anything official Vue document to create HOC. The closest thing I can find on the web is this post https://medium.com/tldr-tech/higher-order-components-in-vue-js-38b500c6d49f and spreading all the properties seem verbose.
I think the popular way to achieve composition in Vue component is to use mixins, and there are some common problems for minxins:
I know for 2 Vue handles conflicting pretty well and for 3, I personally think it would be developer's own fault to using an "escape hatch" to finish complex composition. but still 1 could be a problem. So my next question is, does Vue promotes the use of mixin?
What does the proposed API look like?
Maybe something like
Vue.composite(wrappedComponents, addedProperties)
The text was updated successfully, but these errors were encountered: