React集成react-activation,实现页面缓存

安装

yarn add react-activation

demo1

import { KeepAlive, useActivate, AliveScope } from 'react-activation';
function Counter() {
  const [count, setCount] = useState(0)

  return (
    
count: {count}
) } function App() { const [show, setShow] = useState(true) return (
without {``}
{show && }
with {``}
{show && ( )}
) }

demo2
注:umi案例。AliveScope 设置在 layouts/index.tsx下面
在这里插入图片描述

const Area  = () =>{
	return 
区域管理
} const AreaAlive = memo( ({ location: { pathname } }: API.PagesRouteType) => { return ( {/*页面组件*/} ); }, ); export default AreaAlive;

欢迎留言交流

你可能感兴趣的:(react,umi,react.js,缓存,javascript)