StructureBuilder / react-keep-alive

A component that maintains component state and avoids repeated re-rendering.
MIT License
980 stars 105 forks source link

feat: add remove cache method #97

Open kavience opened 4 years ago

kavience commented 4 years ago

what ?

for solve issue https://github.com/StructureBuilder/react-keep-alive/issues/82, I add remove method.

为了解决 issue https://github.com/StructureBuilder/react-keep-alive/issues/82, 我添加了一个删除缓存的方法。

How to use ?

<KeepAliveProvider
    ref={(ref) => {
    this.keepAliveProviderRef = ref;
    }}
    max={30}
>

</KeepAliveProvider>

First you need get keepAliveProviderRef, and in correct time call it's method named removeCache like this:

首先,需要获取 keepAliveProviderRef ,并在合适的时间调用名为 removeCache 的方法,如下所示:

keepAliveProviderRef.removeCache('KeepAlive');
// or
keepAliveProviderRef.removeCache(['KeepAlive']);

removeCache receive string or string array as params which is name of KeepAlive.

removeCache 接收字符串或者是字符串数组作为参数,参数来源于 KeepAlive 的属性 name。

<KeepAlive name="KeepAlive">test<KeepAlive>

Note

If you use react-router, and need use history.push when removeCache, you must use history.push first and then use removeCache.

如果你使用 react-router, 你必须在使用 removeCache 之前调用 history.push

kavience commented 4 years ago

临时使用方法:

修改 react-keep-alive 版本为我的地址库

    ......
    "react-keep-alive-pro": "^2.5.5",
    ......

其它功能使用方法不变,仅添加一个 removeCache 方法。

Harres-hub commented 2 years ago

How to force rerender (refresh) the keepalive component (page) ?