fix: store axios instance correctly in useState
An axios instance (returned by axios.create()) is itself a callable function. React's useState setter treats any function argument as an updater callback, calling it with the previous state instead of storing it as the new value. This caused setClient(createClient(...)) to invoke the axios instance with null, store the resulting Promise as client, and produce "client.get is not a function (it is undefined)" at runtime. Fix: wrap in an arrow function so React uses the instance as the return value of the updater rather than as the updater itself. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -94,7 +94,7 @@ export function PostizProvider({ children }: { children: React.ReactNode }) {
|
|||||||
const url = (storedUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
const url = (storedUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
||||||
setApiKey(storedKey);
|
setApiKey(storedKey);
|
||||||
setBaseUrl(url);
|
setBaseUrl(url);
|
||||||
setClient(createClient(storedKey, url));
|
setClient(() => createClient(storedKey, url));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
} finally {
|
} finally {
|
||||||
@@ -109,7 +109,7 @@ export function PostizProvider({ children }: { children: React.ReactNode }) {
|
|||||||
await SecureStore.setItemAsync(BASE_URL_STORAGE, newBaseUrl);
|
await SecureStore.setItemAsync(BASE_URL_STORAGE, newBaseUrl);
|
||||||
setApiKey(newApiKey);
|
setApiKey(newApiKey);
|
||||||
setBaseUrl(newBaseUrl);
|
setBaseUrl(newBaseUrl);
|
||||||
setClient(createClient(newApiKey, newBaseUrl));
|
setClient(() => createClient(newApiKey, newBaseUrl));
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user