Next.js Discord

Discord Forum

Update a state in the client side with the server side

Unanswered
Blue Mockingbird posted this in #help-forum
Open in Discord
Avatar
Blue MockingbirdOP
How can I update a state on a client component if a function is called on a server component?
--- For more context:
I'm using function calling with Vercel AI SDK with NextJS.

I'm handling the logic of the function call in the server-side; but I would also want to display a message in the client side whenever a function is called. Example (route.ts):

const stream = OpenAIStream(response, {
experimental_onFunctionCall: async (
{ name, arguments: args },
createFunctionCallMessages,
) => {
if (name === "function_call") {
... update state for the client
---

and on the client if a function is being called, to display the message

6 Replies

Avatar
Blue MockingbirdOP
ping!!
Avatar
Toyger
If I understood you correctly then you probably can use socketio for this.
Avatar
Blue MockingbirdOP
isn't that too overkill?
Avatar
Toyger
from what I understood you want to do it's most convenient way, but maybe I understood it wrong.
Avatar
Blue MockingbirdOP
might be the most convenient, but since I'm using a serverless edge function, not sure if it's possible to be using a websocket on Vercel
Avatar
Toyger
yeah looks like they don't have direct support, but they offer some alternatives for this https://vercel.com/guides/publish-and-subscribe-to-realtime-data-on-vercel