1.0.0 • Published 11 months ago

@nkduy/kdu-to-react v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

kdu-to-react

This works for both Kdu 2 and Kdu 3.

Install

# npm
npm install @nkduy/kdu-to-react
# or yarn
yarn add @nkduy/kdu-to-react

Usage

import React from 'react'
import { render } from 'react-dom'
import toReact from '@nkduy/kdu-to-react'

const KduComponent = {
  data() {
    return {
      count: 0
    }
  },

  render(h) {
    return h(
      'button',
      {
        on: {
          click: () => this.count++
        }
      },
      [this.count]
    )
  }
}

const ReactComponent = toReact(KduComponent)

render(<ReactComponent />, document.getElementById('app'))

Passing Props

By default we pass all props from React to Kdu:

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 Kdu with the passProps option:

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

License

MIT License.

1.0.0

11 months ago