npm

@uni-component/react
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

@uni-component/react npm build status coverage

Unified component for React.

Installation

pnpm add @uni-component/core @uni-component/react
# or with yarn
yarn add @uni-component/core @uni-component/react
# or with npm
npm install @uni-component/core @uni-component/react

Usage

UniComponent to React component:

import { uni2React } from '@uni-component/react'

export const ReactButton = uni2React(UniButton, (props, state, { renders }) => {
  const {
    n,
    rootClass,
    clickAction
  } = state
  const t = props.text ? props.text : renders.defaultRender && renders.defaultRender()
  return (
    <button className={rootClass} type={props.type} onClick={() => clickAction()}>
      <span>
        <>
          {t}
          {` ${n}`}
        </>
      </span>
      {props.appendRender?.()}
    </button>
  )
})

Entry:

/// <reference types="@uni-component/react/platform" />
import { h, Fragment } from '@uni-component/core'
import '@uni-component/react'
import ReactDOM from 'react-dom'

const App = () => {
  return (
    <>
      <ReactButton>child</ReactButton>
      <ReactButton primary={true} text='text'></ReactButton>
    </>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))

JSX with tsconfig: { "jsxFactory": "h", "jsxFragmentFactory": "Fragment" }

Package Sidebar

Install

npm i @uni-component/react

Weekly Downloads

2

Version

0.9.0

License

MIT

Unpacked Size

51.9 kB

Total Files

12

Last publish

Collaborators

  • dolymood