# react-vueable

> Vue3 emulation API called in the react function component

Latest version **0.0.3** (published 2023-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-vueable
pnpm add react-vueable
yarn add react-vueable
bun add react-vueable
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2023-12-07 |
| First published | 2023-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 55.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | lipans |

## Links

- npm: https://www.npmjs.com/package/react-vueable
- Repository: https://github.com/lipans/react-vueable
- Homepage: https://react-vueable.surge.sh
- Issues: https://github.com/lipans/react-vueable/issues
- npm.io page: https://npm.io/package/react-vueable

## Recent versions

- 0.0.3 (latest) — 2023-12-07
- 0.0.2 — 2023-08-21
- 0.0.1 — 2023-08-02

## README

# react-vueable

Vue3 emulation API called in the react function component

[![NPM version](https://img.shields.io/npm/v/react-vueable.svg?style=flat)](https://npmjs.org/package/react-vueable)
[![NPM downloads](http://img.shields.io/npm/dm/react-vueable.svg?style=flat)](https://npmjs.org/package/react-vueable)

## ✨ Features

- Most similar to Vue API, easy to learn and use
- Supports Vue reactive object, such as ref(), reactive()
- Written in TypeScript with predictable static types

## 📚 Homepage

- [https://react-vueable.surge.sh](https://react-vueable.surge.sh)

## 📦 Install

```bash
$ npm install --save react-vueable
# or
$ yarn add react-vueable
# or
$ pnpm add react-vueable
```

## 🔨 Usage

### useReactive

```tsx
import { useReactive } from 'react-vueable';

const state = useReactive<State>({ count: 0, msg: 'hello world!' });

state.count++;
```

[Open demo in CodeSandbox](https://codesandbox.io/s/yw4c6k?file=/App.tsx)

### KeepAlive

```tsx
import { KeepAlive } from 'react-vueable';

export default () => {
  const [index, setIndex] = useState(0);
  const Component = useMemo(
    () => ({ 0: ComponentA, 1: ComponentB })[index]!,
    [index],
  );

  return (
    <KeepAlive>
      <Component key={index} />
    </KeepAlive>
  );
};
```

[Open demo in CodeSandbox](https://codesandbox.io/s/3f8thv?file=/App.tsx)

### nextTick

```tsx
import { useCallback, useState } from 'react';
import { useNextTick } from 'react-vueable';

export default () => {
  const [count, setCount] = useState(0);
  const nextTick = useNextTick();

  const hanldeClick = useCallback(async () => {
    setCount((prev) => prev + 1);
    console.log(document.getElementById('count')?.innerText);
    await nextTick();
    console.log(document.getElementById('count')?.innerText);
  }, []);

  return (
    <div>
      <span id="count">{count}</span>
      <button type="button" onClick={hanldeClick}>
        count+1
      </button>
    </div>
  );
};
```

[Open demo in CodeSandbox](https://codesandbox.io/s/yz8zx6?file=/App.tsx)

### useWatch

```tsx
import { useWatch } from 'react-vueable';

useWatch(
  (newA, oldA) => {
    console.log(`[watch] newA:${newA}; oldA:${oldA}`);
  },
  [a],
);
```

[Open demo in CodeSandbox](https://codesandbox.io/s/ggrrk8?file=/App.tsx)

## LICENSE

MIT

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