git-agent for Reactgit-agent understands React component structure, custom hook patterns, and context changes, producing conventional commit messages that clearly describe UI and state management updates.
diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts
index 2b3f8d1..9c4a7e2 100644
--- a/src/hooks/useAuth.ts
+++ b/src/hooks/useAuth.ts
@@ -1,14 +1,28 @@
-import { useState } from "react";
+import { useState, useCallback } from "react";
import { authClient } from "../lib/auth";
+import type { User } from "../types";
-export function useAuth() {
- const [user, setUser] = useState(null);
- const [loading, setLoading] = useState(false);
+export function useAuth() {
+ const [user, setUser] = useState<User | null>(null);
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState<string | null>(null);
- async function login(email: string, password: string) {
+ const login = useCallback(async (email: string, password: string) => {
+ setError(null);
setLoading(true);
- const result = await authClient.login(email, password);
- setUser(result.user);
- setLoading(false);
- }
+ try {
+ const result = await authClient.login(email, password);
+ setUser(result.user);
+ } catch (err) {
+ setError(err instanceof Error ? err.message : "login failed");
+ } finally {
+ setLoading(false);
+ }
+ }, []);
- return { user, loading, login };
+ return { user, loading, error, login };
}refactor(hooks): stabilise useAuth login callback and surface error state
- wrap login in useCallback to prevent child re-renders on parent updates
- add error state so components can display login failure messages
- add try/finally to guarantee setLoading(false) even on thrown errors
- strengthen types: User | null instead of null, string | null for error
The unstable login reference caused form components to re-register event
handlers on every render; useCallback with an empty dep array fixes the
identity.brew install gitagenthq/tap/git-agent
# inside your React project
git-agent init # reads src/ structure to suggest component scopesWill git-agent separate my component logic from its styles?Does git-agent understand React Server Components?Can git-agent commit Storybook story changes separately?