forked from bestchains/bc-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get qiankun global Data (bestchains#15)
- Loading branch information
zggmd
committed
Mar 16, 2023
1 parent
fee9da9
commit e4a0f2e
Showing
5 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react'; | ||
export default () => { | ||
const [qiankun, setQiankun] = React.useState({}); | ||
|
||
return { qiankun, setQiankun }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Licensed Materials - Property of tenxcloud.com | ||
* (C) Copyright 2023 TenxCloud. All Rights Reserved. | ||
*/ | ||
|
||
/** | ||
* hooks | ||
* @author songsz | ||
* @date 2023-03-16 | ||
*/ | ||
import * as React from 'react'; | ||
import { useModel } from '@umijs/max'; | ||
|
||
export let _qiankunData = {}; | ||
const useQiankunGlobalState = () => { | ||
const u = useModel('@@qiankunStateFromMaster'); | ||
const { setQiankun } = useModel('qiankun'); | ||
React.useEffect(() => { | ||
u.onGlobalStateChange((state, prev) => { | ||
// state: 变更后的状态; prev 变更前的状态 | ||
setQiankun(state); | ||
// 给 app.tsx layout 使用 | ||
_qiankunData?.setInitialState?.(state); | ||
}, true); | ||
}, [setQiankun]); | ||
}; | ||
export { useQiankunGlobalState }; |