# @vue/babel-sugar-composition-api-render-instance

> Babel syntactic sugar for replaceing `this` with `getCurrentInstance()` in Vue JSX with @vue/composition-api

Latest version **1.4.0** (published 2022-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vue/babel-sugar-composition-api-render-instance
pnpm add @vue/babel-sugar-composition-api-render-instance
yarn add @vue/babel-sugar-composition-api-render-instance
bun add @vue/babel-sugar-composition-api-render-instance
```

## 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.4.0 |
| Published | 2022-08-25 |
| First published | 2020-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1476 |
| Author | luwanquan |
| Maintainers | akryum, yyx990803, soda, amour1688 |

## Links

- npm: https://www.npmjs.com/package/@vue/babel-sugar-composition-api-render-instance
- Repository: https://github.com/vuejs/jsx.git#master
- Homepage: https://github.com/vuejs/jsx/tree/master#readme
- Issues: https://github.com/vuejs/jsx/issues
- npm.io page: https://npm.io/package/@vue/babel-sugar-composition-api-render-instance

## Dependencies (1)

- [@babel/plugin-syntax-jsx](https://npm.io/package/@babel/plugin-syntax-jsx.md) ^7.2.0

## Recent versions

- 1.4.0 (latest) — 2022-08-25
- 1.3.0 — 2022-07-06
- 1.2.4 — 2020-10-27
- 1.2.1 — 2020-10-16
- 1.2.0 — 2020-10-16

## README

## @vue/babel-sugar-composition-api-render-instance

> Ported from [luwanquan/babel-preset-vca-jsx](https://github.com/luwanquan/babel-preset-vca-jsx) by [@luwanquan](https://github.com/luwanquan)

Babel syntactic sugar for replacing `this` with `getCurrentInstance()` in Vue JSX with @vue/composition-api

### Babel Compatibility Notes

- This repo is only compatible with Babel 7.x

### Usage

Install the dependencies:

```sh
# for yarn:
yarn add @vue/babel-sugar-composition-api-render-instance
# for npm:
npm install @vue/babel-sugar-composition-api-render-instance --save
```

In your `.babelrc`:

```json
{
  "plugins": ["@vue/babel-sugar-composition-api-render-instance"]
}
```

However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.

### Details

This plugin automatically replaces `this` in `setup()` with `getCurrentInstance()`. This is required for JSX to work in @vue/composition-api as `this` is not available in `setup()`

Input:

```jsx
defineComponent({ 
  setup() {
    return () => <MyComponent vModel={a.b} />
  }
})
```

Output (without @vue/babel-sugar-composition-api-render-instance):

```jsx
defineComponent({
  setup() {
    return () => <MyComponent model={{
      value: a.b,
      callback: $$v => {
        this.$set(a, "b", $$v);
      }
    }} />
  }
})
```

Output (with @vue/babel-sugar-composition-api-render-instance):

```jsx
import { getCurrentInstance } from "@vue/composition-api";

defineComponent({
  setup() {
    const __currentInstance = getCurrentInstance();

    return () => <MyComponent model={{
      value: a.b,
      callback: $$v => {
        __currentInstance.$set(a, "b", $$v);
      }
    }} />
  }
})
```

---
_Source: https://npm.io/package/@vue/babel-sugar-composition-api-render-instance · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
