2.0.0 • Published 2 months ago

@rcp/c.keepalive v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 months ago

@rcp/c.keepalive

NPM version NPM Downloads

Keep react component view / store when switched view rather than unmount it.

Installation

npm install @rcp/c.keepalive
# or use yarn
yarn add @rcp/c.keepalive

Usage

import KeepAlive, { bindKeepAliveLifeCycle } from '@rcp/c.keepalive'
import '@rcp/c.keepalive/style.less'

@bindKeepAliveLifeCycle
class Content extends React.Component {
    // 新增的生命周期
    componentWillActive({newValue, oldValue}) {}
    componentDidActive({newValue, oldValue}) {}
    componentWillUnactive({newValue, oldValue}) {}
    componentDidUnactive({newValue, oldValue}) {}
}

<KeepAlive uniqKey="/home" >
    <Content>Home</Content>
<KeepAlive>
// LifeCycle
// componentWillActive => {newValue: '/home'}
// componentDidActive => {newValue: '/home'}

// Components
// <>
//   <Content>Home</Content>
// </>

// Update
<KeepAlive uniqKey="/detail" >
    <Content>Detail</Content>
<KeepAlive>
// LifeCycle
// componentWillUnactive => {newValue: '/detail', oldValue: '/home'} (Home)
// componentWillActive => {newValue: '/detail', oldValue: '/home'} (Detail)
// componentDidUnactive => {newValue: '/detail', oldValue: '/home'} (Home)
// componentDidActive => {newValue: '/detail', oldValue: '/home'} (Detail)

// Components
// <>
//   <Content (display: none)>Home</Content>
//   <Content>Detail</Content>
// </>

Props

uniqKey

  • Type: string

disabled

  • Type: boolean

Related

Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

License

MIT

2.0.0

2 months ago

1.0.13

2 years ago

1.0.12

3 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago