Open kavience opened 4 years ago
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, 我添加了一个删除缓存的方法。
<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
removeCache 接收字符串或者是字符串数组作为参数,参数来源于 KeepAlive 的属性 name。
<KeepAlive name="KeepAlive">test<KeepAlive>
If you use react-router, and need use history.push when removeCache, you must use history.push first and then use removeCache.
react-router
history.push
如果你使用 react-router, 你必须在使用 removeCache 之前调用 history.push
临时使用方法:
修改 react-keep-alive 版本为我的地址库
react-keep-alive
...... "react-keep-alive-pro": "^2.5.5", ......
其它功能使用方法不变,仅添加一个 removeCache 方法。
How to force rerender (refresh) the keepalive component (page) ?
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 ?
First you need get keepAliveProviderRef, and in correct time call it's method named removeCache like this:
首先,需要获取 keepAliveProviderRef ,并在合适的时间调用名为 removeCache 的方法,如下所示:
removeCache
receive string or string array as params which is name of KeepAlive.removeCache
接收字符串或者是字符串数组作为参数,参数来源于 KeepAlive 的属性 name。Note
If you use
react-router
, and need usehistory.push
when removeCache, you must usehistory.push
first and then use removeCache.如果你使用
react-router
, 你必须在使用removeCache
之前调用history.push