Where did Vue.js come from?
at modernweb.com▼4 up and 1 down, posted by
4 up and 1 down, posted by
I'm aware of that HOC is not React specific. But it works really nicely in React. I'm not sure if the example code in that medium article even is a higher order component? Looks more like it's just'n component inheriting stuff from another component? A HOC is component which gets another component passed in as argument or prop and then returns a new component which wraps that input component somehow.
Those concepts exist in pretty much any programming language. @sylvainpv I'm searching the web for Vue.JS examples where a component gets passed in as prop to another component. Not finding anything so far. Do you know if that is even possible? Doesn't this conflict with the reactive data-structure stuff going on in Vue.JS? To give you a more concrete example: In the last project we needed inline-editing functionality. The goal was to support different input elements like text, select, etc. and the view could also be different from case to case. This was pretty nice and elegant to solve using a higher order component, which basicly looked like this in React: <InlineEdit editComponent={SomeInputComponent} viewComponent={SomeViewComponent} value={val} onChange={(newVal) => { /* do something */}} /> How would you approach that in Vue.JS?Nice! Thanks for the code snippet :-) You are right, that's not any less elegant than in React. Is there also a nice solution for these kind of constructs in Vue.JS? function createComponentWithDefaultProps(Component, defaultProps) { return function(props) { return <Component {...defaultProps} {...props} /> } }