@@ -93,28 +93,39 @@ export function useGitHubLogin(
9393 const popupRef = useRef < PopupWindowPromise | null > ( null ) ;
9494 const [ isLoading , setIsLoading ] = useState ( false ) ;
9595
96+ // Extract individual options to avoid dependency on the whole options object
97+ const {
98+ clientId,
99+ redirectUri = '' ,
100+ scope = 'user:email' ,
101+ popupOptions = { } ,
102+ allowSignup = true ,
103+ onSuccess,
104+ onError,
105+ onRequest,
106+ } = options ;
107+
108+ // Use refs for callbacks to avoid requiring users to memoize them
109+ const onSuccessRef = useRef ( onSuccess ) ;
110+ onSuccessRef . current = onSuccess ;
111+
112+ const onErrorRef = useRef ( onError ) ;
113+ onErrorRef . current = onError ;
114+
115+ const onRequestRef = useRef ( onRequest ) ;
116+ onRequestRef . current = onRequest ;
117+
96118 // Generate state if not provided (for CSRF protection)
97119 const state = useMemo (
98120 ( ) => options . state || generateState ( ) ,
99121 [ options . state ] ,
100122 ) ;
101123
102124 const initiateGitHubLogin = useCallback ( ( ) => {
103- const {
104- clientId,
105- redirectUri = '' ,
106- scope = 'user:email' ,
107- popupOptions = { } ,
108- allowSignup = true ,
109- onSuccess,
110- onError,
111- onRequest,
112- } = options ;
113-
114125 // Validate required props
115126 if ( ! clientId ) {
116127 const error = new Error ( 'clientId is required' ) ;
117- onError ( error ) ;
128+ onErrorRef . current ( error ) ;
118129 return ;
119130 }
120131
@@ -138,7 +149,7 @@ export function useGitHubLogin(
138149
139150 try {
140151 // Call onRequest callback if provided
141- onRequest ?.( ) ;
152+ onRequestRef . current ?.( ) ;
142153
143154 // Open popup window
144155 const popup = openPopupWindow (
@@ -156,25 +167,37 @@ export function useGitHubLogin(
156167
157168 // Verify state matches (CSRF protection)
158169 if ( data . state && data . state !== state ) {
159- onError ( OAuthError . stateMismatch ( ) ) ;
170+ onErrorRef . current ( OAuthError . stateMismatch ( ) ) ;
160171 return ;
161172 }
162173
163174 if ( ! data . code ) {
164- onError ( OAuthError . missingCode ( ) ) ;
175+ onErrorRef . current ( OAuthError . missingCode ( ) ) ;
165176 return ;
166177 }
167- onSuccess ( data ) ;
178+ onSuccessRef . current ( data ) ;
168179 } )
169180 . catch ( ( error : Error ) => {
170181 setIsLoading ( false ) ;
171- onError ( error instanceof Error ? error : new Error ( String ( error ) ) ) ;
182+ onErrorRef . current (
183+ error instanceof Error ? error : new Error ( String ( error ) ) ,
184+ ) ;
172185 } ) ;
173186 } catch ( error ) {
174187 setIsLoading ( false ) ;
175- onError ( error instanceof Error ? error : new Error ( String ( error ) ) ) ;
188+ onErrorRef . current (
189+ error instanceof Error ? error : new Error ( String ( error ) ) ,
190+ ) ;
176191 }
177- } , [ options , state , isLoading ] ) ;
192+ } , [
193+ clientId ,
194+ redirectUri ,
195+ scope ,
196+ popupOptions ,
197+ allowSignup ,
198+ state ,
199+ isLoading ,
200+ ] ) ;
178201
179202 return {
180203 initiateGitHubLogin,
0 commit comments