alitajs / umi-plugin-keep-alive

<KeepAlive> for umijs base on react-activation

Home Page:https://www.npmjs.com/package/umi-plugin-keep-alive

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

配合dva插件一起使用的时候,dispatch更新state时,页面没有更新,切换才能更新视图

ZmSama opened this issue · comments

commented

给个 demo 吧,没用过 dva

缓存的时候要缓存组件,而models里面的数据不能缓存,不然就出现,实际执行代码,而页面没有更新。
所以要对connect这里改造一下,缓存一个组件,这个组件再connectmodels

//connect导出一个组件,里面的props是自己获取的,不会被缓存住

const UserInfo = connect(({ __login,}) => ({
  __login,
}))(UserInfoIndex);

class UserInfoKeep extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }
  render() {
    return (
      <KeepAlive>
      // UserInfo被缓存了
        <UserInfo />
      </KeepAlive>
    );
  }
}
// 最终导出被缓存的组件
export default connect()(UserInfoKeep);

commented

0.0.1-beta.31 修复了这个问题,是 react-activation 的一个历史遗留问题导致的,之前一直没被定位到,昨天修复了,今天 umi-plugin-keep-alive 也修复了此问题

@CMG-CEO 新版本可能不再需要额外的写法来处理,可以试试普通 connect 写法~ 感谢