[项目自荐] Keep-Alive for React DOM - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
monexus
V2EX    React

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

  •  
  •   monexus
    shenjunru Jun 14, 2022 3154 views
    This topic created in 1415 days ago, the information mentioned may be changed or developed.

    Keep-Alive for React DOM

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

    npm install --save react-fiber-keep-alive 
    • 只基于 React FiberReact Hooks
    • 支持原生的 class component 生命周期。
    • 支持原生的 function componenthooks
    • 支持原生的 context 变化。
    • 支持多组件同时 keep-alive
    • 支持 react-dom v16.8+ / v17 / v18 。
    • Demo: react-router v5
    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

    6 replies    2022-06-14 18:35:09 +08:00
    luffy
        1
    luffy  
       Jun 14, 2022
    这里的应用场景是什么?

    什么情况下需要你这个库
    sunburst112
        2
    sunburst112  
       Jun 14, 2022
    @luffy 多 tab 栏切换缓存上一个 tab 组件的状态 类似 vue 的 keep-alive
    sunburst112
        3
    sunburst112  
       Jun 14, 2022
    可以直接包裹 router6 的 outlet 实现效果吗?
    monexus
        4
    monexus  
    OP
       Jun 14, 2022 via iPhone
    @sunburst112 目前没用过 react-router6 ,你可以尝试一下,加几行代码而已
    monexus
        5
    monexus  
    OP
       Jun 14, 2022 via iPhone
    @luffy 提供整个组件树的状态在 unmount 时被保留,再次 mount 后还原。比如页面导航后退还原原来的页面状态
    weeshin
        6
    weeshin  
       Jun 14, 2022
    React 18 不是说要添加这个原生功能了?
    About     Help     Advertise     Blog     API     FAQ     Solana     5718 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 38ms UTC 06:20 PVG 14:20 LAX 23:20 JFK 02:20
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86