# rif-loader

> similar Vue/v-if attribute for React

Latest version **1.0.8** (published 2021-10-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install rif-loader
pnpm add rif-loader
yarn add rif-loader
bun add rif-loader
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-10-28 |
| First published | 2021-08-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 291.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | destLonY |
| Maintainers | baiqie |

## Links

- npm: https://www.npmjs.com/package/rif-loader
- Repository: https://github.com/web-zyqs/rif-loader
- Homepage: https://github.com/web-zyqs/rif-loader#readme
- Issues: https://github.com/web-zyqs/rif-loader/issues
- npm.io page: https://npm.io/package/rif-loader

## Dependencies (4)

- [@babel/types](https://npm.io/package/@babel/types.md) ^7.15.0
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.15.3
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) ^7.15.0
- [@babel/generator](https://npm.io/package/@babel/generator.md) ^7.15.0

## Recent versions

- 1.0.8 (latest) — 2021-10-28
- 1.0.7 — 2021-10-27
- 1.0.6 — 2021-09-02
- 1.0.5 — 2021-09-01
- 1.0.4 — 2021-09-01
- 1.0.3 — 2021-09-01
- 1.0.2 — 2021-08-31
- 1.0.1 — 2021-08-28
- 1.0.0 — 2021-08-28

## README

## rif-loader
react jsx attribute similar Vue/v-if attribute  
帮助实现React框架中，类似Vue的v-if属性

**base effect**：
*原理/作用*
```js
// your code, before transform
// 原代码
const ELEMENT = ({ visible }) => (
  <div>
    <div r-if={visible}>VISIBLE</div>
  </div>
)

// result code
// 转换后代码
const ELEMENT = ({ visible }) => (
  <div>
    {
      visible ? <div>VISIBLE</div> : null
    }
  </div>
)
```
#### 作者 

白切
wechat: feng-baiqie

**初始化**：
```js
npm install --save-dev rif-loader
```

**use with webpack/loader**：

*做为独立的loader来使用*

```js
// webpack.config.js
module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      use: [
        {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-react']
          }
        },
        'rif-loader'
      ]
    },
  ]
}
```
**use with babel-loader/plugins**：

*做为babel-loader中的一个plugin来使用*

```js
// webpack.config.js
const { babelPlugin: rifPlugin } = require('rif-loader')

module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /node_modules/,
      use: [
        {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-react'],
            plugins: [rifPlugin]
          }
        },
      ]
    },
  ]
}
```

**use in react**：
```js
// 普通节点
import { useState } from 'raect'

const Element = () => {
  const [visible, setVisible] = useState(true)

  return (
    <div>
      <div r-if={visible}>ELEMENT</div>
      <button
        onClick={() => setVisible(!visible)}
      >
        visible/hidden
      </button>
    </div>
  )
}
```
```js
// 组件
import { useState, useEffect } from 'raect'

const Component = () => {
  useEffect(() => {
    console.log('effect')
  }, [])

  return (<div>COMPNENT</div>)
}

const Element = () => {
  const [visible, setVisible] = useState(false)

  return (
    <div>
      <Component r-if={visible} />
      <button
        onClick={() => setVisible(!visible)}
      >
        visible/hidden
      </button>
    </div>
  )
}
```

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