Description
From the looks of it, it's not possible to use HOC's in .vue
files because of the way vue-loader
loader works. Instead you have to apply your HOC in a .js
file.
In, for instance, React+Redux containers you would usually define your component and and "connect" it to the store using a HOC from the react-redux package. It could look something like this:
class MyComponent extends React.Component {
render () {
return <div>Hello {this.props.name}</div>
}
}
export default connect(({name}) => ({name}), null)(MyComponent);
When trying to do something similar with .vue
files the render function of the HOC gets replaced instead of the render function of the component you're applying your HOC to.
The following code will cause vue-loader
to replace the render function of the component returned by connect
instead of replacing the render function of MyComponent
:
<template><div>Hello {{name}}</div></template>
<script>
const MyComponent = {
props: ['name']
}
export connect(({name}) => ({name}), null)(MyComponent)
</script>
To work around this you can, in your .vue
, export MyComponent and have a .js
which exports the connected MyComponent
, but i find it unnecessarily complicated.
tl;dr
I want to be able to better reuse code with higher-order functions in Vue, the way you do in e.g. React.