#How would you store a ref of an external packages in a state (useState)

6 messages · Page 1 of 1 (latest)

sacred tusk
#

I have this:

import { useChat } from '@ai-sdk/vue';
const { messages, handleSubmit } = useChat()

handleSubmit is a method and messages is a ref().

How can I wrap this in useState to be able to call handleSubmit and access messages from any component and keep the state alive on route change?

willow tree
sacred tusk
#

Not really, I only want the chat messages / methods etc available across multiple pages/components

#

Currently I do:

const { chat_messages } = useSharedStore()
onBeforeUnmount(() => {
    chat_messages.value = messages
})
onBeforeMount(() => { 
    messages.value = chat_messages.value 
})

But I should do it manually for each item and it's not ideal to keep all duplicated and synced. Ideally I would just have the messages directly in a store

#

@willow tree

#

But it's definitely only needed client side if that simplifies things