@tc-utils/shared
TypeScript icon, indicating that this package has built-in type declarations

1.0.3-rc.0 • Public • Published

@tc-utils/shared

安装

使用 npm:

$ npm i -g npm
$ npm i @tc-utils/shared

使用方法

直接引用 import { withNativeProps } from '@tc-utils/shared'

import React, { useState } from 'react'
import { Input } from './Input'
import styles from './index.module.less'
import ReactDOM from 'react-dom'

const App = () => {
  const [state, setState] = useState<string>()

  return (
    <div className={styles.demo}>
      <div>withNativeProps简单示例</div>
      <div>
        <Input
          onChange={(val) => {
            setState(val)
          }}
          value={state}
          className={styles['demo-input']}
        />
      </div>
    </div>
  )
}

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

Input组件

import { withNativeProps } from '@tc-utils/shared'
import React, { CSSProperties } from 'react'
import styles from './index.module.less'

interface InputProps {
  value?: string
  onChange?: (newVal: string) => void
  className?: string
  style?: CSSProperties
}
export const Input = (props: InputProps) => {
  return withNativeProps(
    props,
    <input
      className={styles['input']}
      onChange={(e) => {
        props.onChange?.(e.target.value)
      }}
      value={props.value}
    />
  )
}

index.module.less

.demo {
  display: flex;
  flex-direction: column;
  row-gap: 10px;
  font-size: 20px;

  &-input {
    color: red;
  }
}

.input {
  margin-right: 10px;
  padding: 4px;
  font-size: 20px;
}

Readme

Keywords

Package Sidebar

Install

npm i @tc-utils/shared

Weekly Downloads

1

Version

1.0.3-rc.0

License

MIT

Unpacked Size

23.4 kB

Total Files

25

Last publish

Collaborators

  • char-big-bear