Next.js Discord

Discord Forum

AI Vercel SDK | React

Unanswered
Ghost ant posted this in #help-forum
Open in Discord
Ghost antOP
onFinish uses a stale value, any idea how to force it to use a fresh state?
const useFoo = () => {
  const [keyword, setKeyword] = React.useState<string>();
  const res = useCompletion({
    onFinish: () => {
      console.log({ keyword }); // undefined | stale value
    },
  });
  const { complete } = res;
  const onTabChange = () => {
    setKeyword("a");
    complete("...");
  };
  return res;
};

1 Reply

Yellow-breasted Bunting
if im not too late @Ghost ant, you can use completion from onFinish(completion) to get the current value