[Day 142] Built a custom Vue composable to handle AI streaming
I wanted to share how I handled streaming on the frontend for our AI chat on SocialMe Ai.
Instead of relying on a library, I built a custom composable (useSocialChat) in Vue/Nuxt.
Core idea:
Handle the entire streaming lifecycle in one place.
What it does:
-> Sends request via fetch
-> Reads response using ReadableStream.getReader()
-> Uses TextDecoder to process chunks
-> Parses structured JSON events
-> Updates the last AI message incrementally
We also handle:
-> tool results mid-stream
-> reactive UI updates
-> loading state
Why this worked well:
-> Keeps UI logic clean
-> Avoids scattered state updates
-> Easy to extend
Big takeaway: Streaming is not just a backend problem. Frontend handling is just as critical for good UX.