diff --git a/package.json b/package.json index c5cbab8e..66c57dcb 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "@umijs/plugin-openapi": "^1.2.0", "@umijs/preset-ant-design-pro": "^1.2.0", "@umijs/preset-dumi": "^1.1.7", - "@umijs/preset-react": "^1.7.4", + "@umijs/preset-react": "^1.8.17", "@umijs/yorkie": "^2.0.3", "carlo": "^0.9.46", "cross-env": "^7.0.0", diff --git a/src/components/RightContent/AvatarDropdown.tsx b/src/components/RightContent/AvatarDropdown.tsx index 74fdce86..d9e67311 100644 --- a/src/components/RightContent/AvatarDropdown.tsx +++ b/src/components/RightContent/AvatarDropdown.tsx @@ -36,14 +36,14 @@ const AvatarDropdown: React.FC = ({ menu }) => { const onMenuClick = useCallback( (event: MenuInfo) => { const { key } = event; - if (key === 'logout' && initialState) { - setInitialState({ ...initialState, currentUser: undefined }); + if (key === 'logout') { + setInitialState((s) => ({ ...s, currentUser: undefined })); loginOut(); return; } history.push(`/account/${key}`); }, - [initialState, setInitialState], + [setInitialState], ); const loading = ( diff --git a/src/pages/user/Login/index.tsx b/src/pages/user/Login/index.tsx index fb5a923f..615e2634 100644 --- a/src/pages/user/Login/index.tsx +++ b/src/pages/user/Login/index.tsx @@ -29,16 +29,6 @@ const LoginMessage: React.FC<{ /> ); -/** 此方法会跳转到 redirect 参数所在的位置 */ -const goto = () => { - if (!history) return; - setTimeout(() => { - const { query } = history.location; - const { redirect } = query as { redirect: string }; - history.push(redirect || '/'); - }, 10); -}; - const Login: React.FC = () => { const [submitting, setSubmitting] = useState(false); const [userLoginState, setUserLoginState] = useState({}); @@ -50,10 +40,10 @@ const Login: React.FC = () => { const fetchUserInfo = async () => { const userInfo = await initialState?.fetchUserInfo?.(); if (userInfo) { - setInitialState({ - ...initialState, + await setInitialState((s) => ({ + ...s, currentUser: userInfo, - }); + })); } }; @@ -69,7 +59,11 @@ const Login: React.FC = () => { }); message.success(defaultloginSuccessMessage); await fetchUserInfo(); - goto(); + /** 此方法会跳转到 redirect 参数所在的位置 */ + if (!history) return; + const { query } = history.location; + const { redirect } = query as { redirect: string }; + history.push(redirect || '/'); return; } // 如果失败去设置用户错误信息