From 4301049553b6c0207e553bbf8c0f6bad673afb5d Mon Sep 17 00:00:00 2001
From: CJY <375564567@qq.com>
Date: Mon, 11 Nov 2019 11:19:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20AliveScope=20=E5=A4=96?=
=?UTF-8?q?=E9=83=A8=E5=91=8A=E8=AD=A6=EF=BC=9B=E4=BF=AE=E5=A4=8D=20saveSc?=
=?UTF-8?q?rollPosition=20=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98=EF=BC=88?=
=?UTF-8?q?=E7=BC=BA=E5=A4=B1=20value=20=E5=87=BD=E6=95=B0=EF=BC=89?=
=?UTF-8?q?=EF=BC=9B=E4=BF=AE=E5=A4=8D=20saveScrollPosition=20=E5=AF=B9?=
=?UTF-8?q?=E5=B1=8F=E5=B9=95=E6=BB=9A=E5=8A=A8=E5=85=83=E7=B4=A0=E7=9A=84?=
=?UTF-8?q?=E4=B8=8D=E6=A0=87=E5=87=86=E6=8E=A2=E6=B5=8B=E6=96=B9=E5=BC=8F?=
=?UTF-8?q?=EF=BC=9BKeepAlive=20=E7=9E=AC=E6=97=B6=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E9=94=81=E5=91=8A=E8=AD=A6=E6=9B=BF=E6=8D=A2=E4=B8=BA=E8=8B=B1?=
=?UTF-8?q?=E6=96=87=EF=BC=8C=E4=B8=8E=E4=B8=96=E7=95=8C=E6=8E=A5=E8=BD=A8?=
=?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0=20README=EF=BC=8C=E8=AF=B4=E6=98=8E?=
=?UTF-8?q?=20AliveScope=20=E4=BD=BF=E7=94=A8=E6=96=B9=E5=BC=8F=E4=B8=8E?=
=?UTF-8?q?=E6=B3=A8=E6=84=8F=E7=82=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 71 ++++++++++++++++-------------
README_CN.md | 74 +++++++++++++++++--------------
package.json | 2 +-
src/core/KeepAlive.js | 6 +--
src/core/withAliveScope.js | 40 ++++++++++++-----
src/helpers/base/try/index.js | 6 +++
src/helpers/saveScrollPosition.js | 9 ++--
7 files changed, 124 insertions(+), 84 deletions(-)
diff --git a/README.md b/README.md
index 5cd4977..be24933 100644
--- a/README.md
+++ b/README.md
@@ -40,9 +40,9 @@ npm install react-activation
## Usage
-Add `react-activation/babel` plugins in `.babelrc`
+#### 1. Add `react-activation/babel` plugins in `.babelrc`
-The plugin adds a `_ka` attribute to each JSX element during compilation to help the `` runtime generate a unique identifier by render location.
+The plugin adds a `_ka` attribute to each JSX element during compilation to help the `react-activation` runtime **generate an unique identifier by render location**.
```javascript
{
@@ -52,57 +52,64 @@ The plugin adds a `_ka` attribute to each JSX element during compilation to help
}
```
-In your business code
+#### 2. In your business code, place the `` outer layer at a location that will not be unmounted, usually at the application entrance
+
+Note: When used with `react-router` or `react-redux`, you need to place `` inside `` or ``
```javascript
-import React, { Component, useState } from 'react'
+// entry.js
+
+import React from 'react'
import ReactDOM from 'react-dom'
-import KeepAlive, { AliveScope, withActivation } from 'react-activation'
+import { AliveScope } from 'react-activation'
-@withActivation
-class Test extends Component {
- state = {
- count: 0
- }
+import Test from './Test'
- setCount = count => this.setState({ count })
+ReactDOM.render(
+
+
+ ,
+ document.getElementById('root')
+)
+```
- componentDidActivate() {
- console.log('Test: componentDidActivate')
- }
+#### 3. Wrap the components that need to keep states with ``
- componentWillUnactivate() {
- console.log('Test: componentWillUnactivate')
- }
+Like the `` component in the example
- render() {
- const { count } = this.state
-
- return (
-