Keep-Alive for React DOM
https://github.com/shenjunru/react-fiber-keep-alive
npm install --save react-fiber-keep-alive
- 只基于
React Fiber和React Hooks。 - 支持原生的
class component生命周期。 - 支持原生的
function component的hooks。 - 支持原生的
context变化。 - 支持多组件同时
keep-alive。 - 支持
react-domv16.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