react-activation
github:react-activation 中文说明
KeepAlive组件嵌套在AliveScope作用域下即可:
import KeepAlive, { AliveScope } from 'react-activation'
function App() {
// ...
return (
<AliveScope>
<App>
<KeepAlive>
<Page />
</KeepAlive>
</App>
</AliveScope>
);
}
UmiMax中使用
使用UmiMax脚手架搭建的项目没有暴露App组件和ReactDOM.render()
需要在app.tsx文件中导出相关函数:
// app.tsx
// ...
import { AliveScope } from 'react-activation'
export function rootContainer(container: React.ReactNode) {
return <AliveScope>{container}</AliveScope>
}