From c89f61a77fdb0c7f3a340033d2aaaae0ae56ce46 Mon Sep 17 00:00:00 2001 From: billisdead Date: Sat, 16 May 2026 12:31:27 +0200 Subject: [PATCH] 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 --- artifacts/postiz-mobile/context/PostizContext.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/artifacts/postiz-mobile/context/PostizContext.tsx b/artifacts/postiz-mobile/context/PostizContext.tsx index 4ae025a..64bb15f 100644 --- a/artifacts/postiz-mobile/context/PostizContext.tsx +++ b/artifacts/postiz-mobile/context/PostizContext.tsx @@ -94,7 +94,7 @@ export function PostizProvider({ children }: { children: React.ReactNode }) { const url = (storedUrl || DEFAULT_BASE_URL).replace(/\/$/, ""); setApiKey(storedKey); setBaseUrl(url); - setClient(createClient(storedKey, url)); + setClient(() => createClient(storedKey, url)); } } catch { } finally { @@ -109,7 +109,7 @@ export function PostizProvider({ children }: { children: React.ReactNode }) { await SecureStore.setItemAsync(BASE_URL_STORAGE, newBaseUrl); setApiKey(newApiKey); setBaseUrl(newBaseUrl); - setClient(createClient(newApiKey, newBaseUrl)); + setClient(() => createClient(newApiKey, newBaseUrl)); }, [] );