diff --git a/resources/ts/hooks/useAuth.ts b/resources/ts/hooks/useAuth.ts index 59f0fc4..b858039 100644 --- a/resources/ts/hooks/useAuth.ts +++ b/resources/ts/hooks/useAuth.ts @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useState, useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { RootState } from '@/store/store'; import { setUserData, clearUserData } from '@/store/slice/userSlice'; @@ -21,7 +21,7 @@ export function useAuth() { } }, []); - const fetchUser = async (navigate?: (path: string) => void) => { + const fetchUser = useCallback(async (navigate?: (path: string) => void) => { try { const response = await axiosClient.get('/user', { headers: { @@ -50,7 +50,7 @@ export function useAuth() { } finally { setIsLoading(false); } - }; + }, [dispatch, fetchContracts]); const login = async (token: string, navigate?: (path: string) => void) => { if (!token) { diff --git a/resources/ts/layouts/AdminLayout.tsx b/resources/ts/layouts/AdminLayout.tsx index 8fd3a0e..f9510a2 100644 --- a/resources/ts/layouts/AdminLayout.tsx +++ b/resources/ts/layouts/AdminLayout.tsx @@ -44,9 +44,6 @@ const AdminLayout: React.FC = ({ currentContract ?? defaultContract, ); - const [refreshKey, setRefreshKey] = useState(0); - - // Asegurarnos de que el valor del Dropdown sea un número válido const dropdownValue = contract?.id ?? 0; useEffect(() => { @@ -67,7 +64,6 @@ const AdminLayout: React.FC = ({ dispatch(selectContract(selectedContract.id!)); setContract(selectedContract); - setRefreshKey((prev) => prev + 1); // Force children re-render } catch (error: any) { console.error( 'Error saving selected contract:', @@ -368,7 +364,7 @@ const AdminLayout: React.FC = ({ )} -
+
{children}