# umi-plugin-dvax

> xstate like usage of dva in umi

Latest version **1.1.0** (published 2024-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install umi-plugin-dvax
pnpm add umi-plugin-dvax
yarn add umi-plugin-dvax
bun add umi-plugin-dvax
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2024-02-27 |
| First published | 2022-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | 郑家豪 |
| Maintainers | zhengjiahao |
| Keywords | umi, dva |

## Links

- npm: https://www.npmjs.com/package/umi-plugin-dvax
- Repository: https://github.com/Soundmark/plugin-dvax
- Homepage: https://github.com/Soundmark/plugin-dvax#readme
- Issues: https://github.com/Soundmark/plugin-dvax/issues
- npm.io page: https://npm.io/package/umi-plugin-dvax

## Recent versions

- 1.1.0 (latest) — 2024-02-27
- 1.0.5 — 2022-11-11
- 1.0.3 — 2022-07-19
- 1.0.2 — 2022-07-14
- 1.0.1 — 2022-07-14
- 1.0.0 — 2022-07-14

## README

# Plugin-dvax

umi 插件，dva 用法封装

## Install

`yarn add umi-plugin-dvax`

## Usage

启用插件，在.umirc.ts：

```ts
export default defineConfig({
  dva: {
    // 跳过model检测
    skipModelValidate: true,
  },
});
```

在 model 文件内:

```typescript
import { createModel } from "@@/plugin-dvax";

interface Param {
  a: number;
}

export default createModel<Param>({
  namespace: "test-model",
  state: {
    a: 1,
  },
  // 自定义reducer
  reducer: {
    add: (state, action) => {
      return {
        ...state,
        a: state.a + 1,
      };
    },
  },
});
```

在组件内使用：

```tsx
export default function Index() {
  // 响应式获取数据
  const { a } = useSelector(testModel.selector);

  // 非响应式获取数据
  const getState = () => {
    const { a } = testModel.getState();
    return a;
  };

  // 修改
  const update = () => {
    testModel.actions.update({ a: a + 1 });
  };

  // 重置
  const reset = () => {
    testModel.actions.reset();
  };

  // dispatch
  const add = () => {
    testModel.dispatch("add");
  };

  return <div>{a}</div>;
}
```

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