1.0.17 • Published 1 year ago

wang-enum-react v1.0.17

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

在React中使用

安装

npm install wang-enum-react

方法

getDescByValue 根据名称获取键值 getDescValueList 根据集合名称获取集合数组

import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import WangEnumReact from 'wang-enum-react'

const enumInfo = {
  // 枚举示例
  COLORS: {
    RED: { value: 1, desc: 'Red' },
    BLUE: { value: 2, desc: 'Blue' },
  },
}

WangEnumReact.install(React, { enumInfo })

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

使用枚举

使用高阶函数

import React, { useContext } from 'react';
import {withEnum, EnumContext } from 'wang-enum-react';

const MyComponent = () => {
  const Enum = useContext(EnumContext);

  return (
    <div>
      <p>{Enum.getDescByValue('COLORS', 1)}</p>
    </div>
  );
};

export default withEnum(MyComponent);

使用类函数

import React, { useContext } from 'react';

class  MyComponent extends React.Component  {

  render(){
    return (
    <div>
      <p>{this.$enum.getDescByValue('COLORS', 1)}</p>
    </div>
  );
  }
};

export default MyComponent;
1.0.17

1 year ago

1.0.16

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago