# umi-plugin-keep-alive

> for umi base on react-activation

Latest version **0.0.1-beta.35** (published 2022-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install umi-plugin-keep-alive
pnpm add umi-plugin-keep-alive
yarn add umi-plugin-keep-alive
bun add umi-plugin-keep-alive
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-beta.35 |
| Published | 2022-11-01 |
| First published | 2019-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 293 |
| Maintainers | sorrycc, cjy0208, xiaohuoni |
| Keywords | React Keep Alive, Keep Alive, keep-alive, KeepAlive, react-activation, activation, react cache, umi keep alive, umijs, cache |

## Links

- npm: https://www.npmjs.com/package/umi-plugin-keep-alive
- Repository: https://github.com/alitajs/umi-plugin-keep-alive
- npm.io page: https://npm.io/package/umi-plugin-keep-alive

## Dependencies (1)

- [react-activation](https://npm.io/package/react-activation.md) ^0.12.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.0.1-beta.35 (latest) — 2022-11-01
- 0.0.1-beta.34 — 2022-07-12
- 0.0.1-beta.33 — 2022-06-27
- 0.0.1-beta.32 — 2022-06-27
- 0.0.1-beta.31 — 2022-05-24
- 0.0.1-beta.30 — 2022-01-04
- 0.0.1-beta.29 — 2021-07-01
- 0.0.1-beta.28 — 2021-05-28
- 0.0.1-beta.27 — 2021-04-29
- 0.0.1-beta.26 — 2021-03-29
- 0.0.1-beta.25 — 2021-03-28
- 0.0.1-beta.24 — 2021-03-18
- 0.0.1-beta.23 — 2021-03-05
- 0.0.1-beta.22 — 2021-01-30
- 0.0.1-beta.21 — 2021-01-26
- … 18 more at https://npm.io/package/umi-plugin-keep-alive/versions

## README

# umi-plugin-keep-alive

中文说明 | [English](./README_EN.md)

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

此 `<KeepAlive>` 功能基于 [react-activation](https://github.com/CJY0208/react-activation/blob/master/README_CN.md)

## 在线示例

umi 多 tabs 示例：https://codesandbox.io/s/umi-keep-alive-tabs-demo-knfxy

## 使用方法

1. 安装

    ```bash
    npm install umi-plugin-keep-alive --save
    # or
    yarn add umi-plugin-keep-alive
    ```

2. 从 `umi` 中导出 `KeepAlive`，包裹在需要被缓存的组件上

    ```javascript
    import { useState } from 'react'
    import { KeepAlive } from 'umi'

    function Counter() {
      const [count, setCount] = useState(0)

      return (
        <div>
          <p>count: {count}</p>
          <button onClick={() => setCount(count => count + 1)}>add</button>
        </div>
      )
    }

    export default function() {
      const [show, setShow] = useState(true)

      return (
        <div>
          <h1>Page index</h1>
          {show && (
            <KeepAlive>
              <Counter />
            </KeepAlive>
          )}
          <button onClick={() => setShow(show => !show)}>toggle</button>
        </div>
      )
    }
    ```

## 文档

所有来自 [react-activation](https://github.com/CJY0208/react-activation/blob/master/README_CN.md) 都可以由 `umi` 导出

```javascript
import {
  KeepAlive,
  useActivate, 
  useUnactivate, 
  withActivation,
  withAliveScope, 
  useAliveController
} from 'umi'
```

访问 [react-activation](https://github.com/CJY0208/react-activation/blob/master/README_CN.md) 查阅完整的文档

## LICENSE

MIT

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