Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useQiankunStateForSlave 中如何拿到 modal 中更新后的数据同步给子应用 #975

Closed
AlexVagrant opened this issue Oct 22, 2024 · 1 comment

Comments

@AlexVagrant
Copy link

AlexVagrant commented Oct 22, 2024

@umijs/plugin-qiankun 2.44.1
主应用:使用 Ant Design Pro v4 创建的,使用 model 管理数据,
在主应用 app.ts 中使用 useQiankunStateForSlave 同步数据给子应用共享
在子应用中使用@umijs/max 4.2.11 提供的 useModel('@@qiankunStateFromMaster')获取主应用数据

场景:一些用户数据会随着操作(登录/登出/切换用户)变化
问题:如何监听model 管理数据的变化,并将这个变化同步给子应用?

@AlexVagrant
Copy link
Author

// src/index.ts
import { useModel } from "umi";

function MasterPage() {
  const { masterState, setMasterState } = useModel("@@qiankunStateForSlave");

  return (
    <div>
      <button onClick={() => setMasterState("Hello Qiankun")}>
        修改全局 state
      </button>
      {masterState}
    </div>
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant