mirror of
https://github.com/moda-gov-tw/tw-did.git
synced 2026-01-10 21:27:55 -05:00
fix: fix infinity re-redner
This commit is contained in:
@@ -4,9 +4,10 @@ import {
|
||||
useCredentials,
|
||||
} from '@tw-did/react-library';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export function CredentialView() {
|
||||
const { logout } = useAuth();
|
||||
const { logout, user } = useAuth();
|
||||
const { credentials } = useCredentials();
|
||||
|
||||
const handleDownload = async (data: any) => {
|
||||
@@ -34,9 +35,9 @@ export function CredentialView() {
|
||||
};
|
||||
|
||||
/* TODO: get from AuthContext */
|
||||
const checkLogin = () => {
|
||||
return localStorage.getItem('user') ? true : false;
|
||||
};
|
||||
const checkLogin = useCallback(() => {
|
||||
return !!user;
|
||||
}, [user]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -44,7 +45,7 @@ export function CredentialView() {
|
||||
credentials={credentials}
|
||||
actionLabels={['download']}
|
||||
onAction={(index, label) => {
|
||||
if (label == 'download')
|
||||
if (label === 'download')
|
||||
handleDownload(credentials[index].verifiableCredential);
|
||||
else return;
|
||||
}}
|
||||
|
||||
@@ -11,10 +11,13 @@ export interface DialogProps {
|
||||
|
||||
export const useDialog = () => {
|
||||
const [props, setProps] = useState<DialogProps | undefined>();
|
||||
const open = useCallback((openProps: DialogProps) => {
|
||||
openProps && setProps(openProps);
|
||||
}, []);
|
||||
const close = useCallback(() => setProps(undefined), []);
|
||||
const open = useCallback(
|
||||
(openProps: DialogProps) => {
|
||||
openProps && setProps(openProps);
|
||||
},
|
||||
[setProps]
|
||||
);
|
||||
const close = useCallback(() => setProps(undefined), [setProps]);
|
||||
|
||||
const dialogController = useMemo(
|
||||
() => ({ open, close, props }),
|
||||
|
||||
@@ -143,12 +143,6 @@ export const CredentialScreen = ({
|
||||
dialogController.open(errorDialog);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!checkLogin()) {
|
||||
dialogController.open(goHomeDialog);
|
||||
}
|
||||
}, [dialogController, checkLogin]);
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<div className={styles.CredentialScreen}>
|
||||
|
||||
Reference in New Issue
Block a user