File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -68,8 +68,15 @@ export const createRequest = (
6868} ;
6969
7070export const useAPIClient = ( ) : HttpClient => {
71- const { getToken } = getConfig ( ) ;
72- const request = createRequest ( getToken , getBaseUrl ( ) ) ;
71+ // Lazily resolve config at request time so that setConfig()
72+ // can be called during app startup (e.g. in a useEffect)
73+ // before any API calls are executed.
74+ const request = async < T > ( config : RequestConfig ) : Promise < T > => {
75+ const { getToken } = getConfig ( ) ;
76+ const baseUrl = getBaseUrl ( ) ;
77+ const doRequest = createRequest ( getToken , baseUrl ) ;
78+ return doRequest < T > ( config ) ;
79+ } ;
7380
7481 return {
7582 get : < T > ( endpoint : string , params ?: Record < string , any > ) =>
@@ -86,7 +93,7 @@ export const useAPIClient = (): HttpClient => {
8693} ;
8794
8895export const getBaseUrl = ( ) : string => {
89- const url = getConfig ( ) . API_BASE_URL ;
96+ const url = getConfig ( ) . API_BASE_URL ;
9097 if ( ! url ) {
9198 throw new Error ( "API_BASE_URL is not configured. Check your .env file." ) ;
9299 }
You can’t perform that action at this time.
0 commit comments