ai icon indicating copy to clipboard operation
ai copied to clipboard

Add helper to useChat to completely reset the hook states

Open oalexdoda opened this issue 7 months ago • 1 comments

Feature Description

The issue mentioned under https://github.com/vercel/ai/issues/819 is not unique to isLoading. Other parameters like data (containing payloads from the server) remain cached per id even if the id changes. Which, without the stream resuming, is useless. If those states aren't designed to reset for some reason, there should be a resetHook helper to set all values to their default values.

Use Case

An external useEffect that can listen to the externally provided id and reset the useChat() to default as needed.

Additional context

No response

oalexdoda avatar Dec 04 '23 16:12 oalexdoda

I'm exploring https://github.com/vercel/ai/pull/828 for this. You can just change key to reset (see test case)

lgrammel avatar Dec 05 '23 19:12 lgrammel