# react-element-plus

> 曾经使用 Vue 的同学，还记得 v-if 吗？很可惜，在 React 并没有，这有点不爽快，于是这个库组件就诞生了！

Latest version **0.1.2** (published 2019-11-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-element-plus
pnpm add react-element-plus
yarn add react-element-plus
bun add react-element-plus
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2019-11-06 |
| First published | 2019-11-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 36.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kyo4311 |
| Maintainers | kyo4311 |
| Keywords | react, v-if, v-for |

## Links

- npm: https://www.npmjs.com/package/react-element-plus
- Repository: https://github.com/kyo4311/react-element-plus
- Homepage: https://github.com/kyo4311/react-element-plus#readme
- Issues: https://github.com/kyo4311/react-element-plus/issues
- npm.io page: https://npm.io/package/react-element-plus

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^16.10.2
- [react-dom](https://npm.io/package/react-dom.md) ^16.10.2
- [react-scripts](https://npm.io/package/react-scripts.md) 0.9.5

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2019-11-06
- 0.1.1 — 2019-11-06
- 0.1.0 — 2019-11-06

## README

曾经使用 Vue 的同学，还记得 v-if 吗？很可惜，在 React 并没有，这有点记我不爽，于是这个库组件就诞生了！

## Install

```
npm install -D react-element-plus
```

## If/Then/Else

```js
import React, { Component } from 'react'
import v from 'react-element-plus'

// 用v生成的代码，页面上是不会有标签生成的
class App extends Component {
   state = {
      value: 1
   }
   render() {
      return (
         <v.if value={false}>
            <v.then>abc</v.then>
            <v.else>ddd</v.else>
         </v.if>
      )
   }
}
```

[![Edit v.if](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/silly-tharp-rsw7q?fontsize=14)

```js
import React, { Component } from 'react'
import v, { createElements } from 'react-element-plus'
const [div, span] = createElements('div', 'span')

// 用div,sapn可以生成div和span标签，也能传入className等属性
class App extends Component {
   state = {
      value: 1
   }
   render() {
      return (
         <div.if className='div-box' value={false}>
            <span.then>abc</span.then>
            <v.else>ddd</v.else>
         </div.if>
      )
   }
}
```

[![Edit v.if](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/vif-kk9oj?fontsize=14)

## Switch/Case

```js
import React from 'react'
import ReactDOM from 'react-dom'
import v, { createElements } from 'react-element-plus'
const [div, span] = createElements('div', 'span')
import './styles.css'

class App extends React.Component {
   state = {
      value: 3
   }

   render() {
      return (
         <div className='App'>
            <div.switch className='box' value={this.state.value}>
               <span.case value={1} className='red'>
                  Show then
               </span.case>
               <span.case value={2} className='blue'>
                  Show else
               </span.case>
               <span.default>Show default</span.default>
            </div.switch>
         </div>
      )
   }
}
```

[![Edit switch-case](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/vif-2ebco?fontsize=14)

## For

```js
import React from 'react'
import ReactDOM from 'react-dom'
import v, { createElements } from 'react-element-plus'
const [div, span] = createElements('div', 'span')
import './styles.css'

class App extends React.Component {
   state = {
      list: [{ n: 'a' }, { n: 'b' }, { n: 'c' }]
   }

   render() {
      return (
         <div className='App'>
            <v.for
               value={this.state.list}
               render={(item, index) => {
                  return (
                     <div key={index}>
                        {index} - {item.n}
                     </div>
                  )
               }}></v.for>
         </div>
      )
   }
}
```

[![Edit switch-case](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/switch-case-1gz6n?fontsize=14)

---
_Source: https://npm.io/package/react-element-plus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
