本页还没有译文
本页 9 段还没译成Español,下面显示的是英文原文。React error "Maximum update depth exceeded"
还没翻译译自英文(ai-sdk.dev)本页 9 段都还没译
Issue
I am using the AI SDK in a React project with the useChat or useCompletion hooks
and I get the following error when AI responses stream in: Maximum update depth exceeded.
Background
By default, the UI is re-rendered on every chunk that arrives. This can overload the rendering, especially on slower devices or when complex components need updating (e.g. Markdown). Throttling can mitigate this.
Solution
Use the throttle option to throttle the UI updates:
useChat
const { messages } = useChat({
// Throttle the messages and data updates to 50ms:
throttle: 50,
});useCompletion
const { completion } = useCompletion({
// Throttle the completion and data updates to 50ms:
throttle: 50,
});AI 翻译查看英文原文