Giter Site home page Giter Site logo

vip55zxc / umi-plugin-keep-alive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alitajs/umi-plugin-keep-alive

1.0 0.0 0.0 68 KB

<KeepAlive> for umijs base on react-activation

Home Page: https://www.npmjs.com/package/umi-plugin-keep-alive

License: MIT License

JavaScript 74.47% CSS 0.71% Smarty 24.82%

umi-plugin-keep-alive's Introduction

umi-plugin-keep-alive

中文说明 | English

NPM version NPM downloads

<KeepAlive> 功能基于 react-activation

在线示例

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

使用方法

  1. 安装

    npm install umi-plugin-keep-alive --save
    # or
    yarn add umi-plugin-keep-alive
  2. umi 中导出 KeepAlive,包裹在需要被缓存的组件上

    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 都可以由 umi 导出

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

访问 react-activation 查阅完整的文档

LICENSE

MIT

umi-plugin-keep-alive's People

Contributors

303394539 avatar chj-damon avatar cjy0208 avatar js-an avatar sorrycc avatar xiaohuoni avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.