# swc-plugin-jsx-control-statements-v2

> SWC plugin for jsx-control-statements

Latest version **0.3.0** (published 2024-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install swc-plugin-jsx-control-statements-v2
pnpm add swc-plugin-jsx-control-statements-v2
yarn add swc-plugin-jsx-control-statements-v2
bun add swc-plugin-jsx-control-statements-v2
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2024-04-04 |
| First published | 2024-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 818.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | intpp |
| Maintainers | zian502 |
| Keywords | react, jsx, if, else, swc, swc-plugin, jsx-control-statements, react-component |

## Links

- npm: https://www.npmjs.com/package/swc-plugin-jsx-control-statements-v2
- Repository: https://github.com/intpp/swc-plugin-jsx-control-statements
- Homepage: https://github.com/intpp/swc-plugin-jsx-control-statements#readme
- Issues: https://github.com/intpp/swc-plugin-jsx-control-statements/issues
- npm.io page: https://npm.io/package/swc-plugin-jsx-control-statements-v2

## 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.3.0 (latest) — 2024-04-04

## README

# 🦀 JSX control statements for swc

Original idea: [babel-plugin-jsx-control-statements](https://github.com/AlexGilleran/jsx-control-statements)

## Installation

**pnpm** (recommended):

```shell
pnpm i -D swc-plugin-jsx-control-statements
```

or **yarn**

```shell
yarn add -D swc-plugin-jsx-control-statements
```

## Configure `swc`

In your SWC config, you have to add to [`jsc.experimental.plugins`](https://swc.rs/docs/configuration/compilation#jscexperimentalplugins) - `['swc-plugin-jsx-control-statements', {}]`, like in the following code:

```javascript
jsc: {
    experimental: {
        plugins: [
            ['swc-plugin-jsx-control-statements', {}],
        ],
    },
},
```

## Usage

### `<If>` tag

```jsx
import React from 'react';

const Greeting = () => {
  const [closed, setClosed] = useState(false);
  
  return (
      <>
          <If condition={!closed}>
              Hello,
          </If>
          World
          <If condition={!closed}>
            <button onClick={() => setClosed(true)}>Close</button>
          </If>
      </>
  )
};
```


### `<Choose>` tag (if - else if - else condition)

```jsx
import React from 'react';

const Greeting = () => {
  const [closed, setClosed] = useState(false);
  
  return (
      <>
          <Choose>
              <When condition={!closed}>
                  Hello,
              </When>
              <Otherwise>
                  Bye,
              </Otherwise>
          </Choose>
          World
          <If condition={!closed}>
            <button onClick={() => setClosed(true)}>Close</button>
          </If>
      </>
  )
};
```


**TODO:**
- [ ] Support `<For />` tag

---
_Source: https://npm.io/package/swc-plugin-jsx-control-statements-v2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
