Checkpoint: Correction de l'erreur React "Cannot update a component while rendering" dans Home.tsx. L'appel de setLocation pour la redirection automatique des admins a été déplacé dans un useEffect pour respecter les règles de React et éviter les mises à jour de composants pendant le rendu.
This commit is contained in:
@@ -4,11 +4,18 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
||||
import { APP_LOGO, APP_TITLE, getLoginUrl } from "@/const";
|
||||
import { GraduationCap, Calendar, Users, CheckCircle, Mail, Download } from "lucide-react";
|
||||
import { useLocation } from "wouter";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function Home() {
|
||||
const { user, loading, isAuthenticated } = useAuth();
|
||||
const [, setLocation] = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && isAuthenticated && user?.role === 'admin') {
|
||||
setLocation('/admin');
|
||||
}
|
||||
}, [loading, isAuthenticated, user?.role, setLocation]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
@@ -18,7 +25,6 @@ export default function Home() {
|
||||
}
|
||||
|
||||
if (isAuthenticated && user?.role === 'admin') {
|
||||
setLocation('/admin');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user