Skip to content

Commit

Permalink
Merge pull request #2 from egoist/feat/pass-props
Browse files Browse the repository at this point in the history
feat: allow to pass props
  • Loading branch information
egoist authored Jul 7, 2019
2 parents bca5fc0 + 3c7fedb commit f08fbd4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ const ReactComponent = toReact(VueComponent)
render(<ReactComponent />, document.getElementById('app'))
```

### Passing Props

By default we pass all props from React to Vue:

```js
const Counter = toReact({
props: ['initialCount'],
render(h) {
return h('button', {}, [this.initialCount])
}
})

const App = <Counter initialCount={0} />
```

However you can customize how the props are passed to Vue with the `passProps` option:

```js
toReact(VueComponent, {
// Only pass `initialProps` prop
passProps: props => ({ initialCount: props.initialProps }),
// Or disable props
passProps: false
})
```

## Contributing

1. Fork it!
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react'
import Vue from 'vue'

export default Component => {
return () => {
const defaultPassProps = props => props

export default (Component, { passProps = defaultPassProps } = {}) => {
return props => {
const el = React.useRef(null)

React.useEffect(() => {
const app = new Vue({
el: el.current,
render: h => h(Component)
render: h => h(Component, { props: passProps ? passProps(props) : {} })
})

return () => app.$destroy()
Expand Down

0 comments on commit f08fbd4

Please sign in to comment.