Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@hzzt/umi-plugin-keep-alive

alitajs30MIT0.0.5

<KeepAlive> for umi base on react-activation

React Keep Alive, Keep Alive, keep-alive, KeepAlive, react-activation, activation, react cache, umi keep alive, umijs

readme

umi-plugin-keep-alive

NPM version NPM downloads

<KeepAlive> for umijs base on react-activation

Usage

  1. Install

     npm install umi-plugin-keep-alive --save
     # or
     yarn add umi-plugin-keep-alive
  2. export KeepAlive from umi and wrap any component you want to be keeped

     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>
       )
     }

Options

TODO

Documentation

All function of react-activation can be completely imported from umi

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

Visit react-activation for full documentation

LICENSE

MIT