[项目自荐] Keep-Alive for React DOM

2022-06-14 17:51:23 +08:00
 monexus

Keep-Alive for React DOM

https://github.com/shenjunru/react-fiber-keep-alive

npm install --save react-fiber-keep-alive
import React from 'react';
import ReactDOM from 'react-dom';
import KeepAlive from 'react-fiber-keep-alive';

const root = document.getElementById('root');

ReactDOM.render((
    <KeepAlive.Provider value={root}>
        ...
        <KeepAlive name="test">
            <YourComponent />
        </KeepAlive>
        ...
    </KeepAlive.Provider>
), root);

目前版本 0.6.2, 欢迎试用,提 bug

2021 次点击
所在节点    React
6 条回复
luffy
2022-06-14 18:03:27 +08:00
这里的应用场景是什么?

什么情况下需要你这个库
sunburst112
2022-06-14 18:05:49 +08:00
@luffy 多 tab 栏切换缓存上一个 tab 组件的状态 类似 vue 的 keep-alive
sunburst112
2022-06-14 18:07:20 +08:00
可以直接包裹 router6 的 outlet 实现效果吗?
monexus
2022-06-14 18:10:55 +08:00
@sunburst112 目前没用过 react-router6 ,你可以尝试一下,加几行代码而已
monexus
2022-06-14 18:18:07 +08:00
@luffy 提供整个组件树的状态在 unmount 时被保留,再次 mount 后还原。比如页面导航后退还原原来的页面状态
weeshin
2022-06-14 18:35:09 +08:00
React 18 不是说要添加这个原生功能了?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/859588

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX