Next.js Discord

Discord Forum

api call not going through

Unanswered
Rex posted this in #help-forum
Open in Discord
RexOP
here is code
  const {
    messages,
    setMessages,
    input,
    handleInputChange,
    handleSubmit,
    isLoading,
    reload,
  } = useChat({
    api: "/api/chat",
    onResponse(response: any) {
      console.log("my response use chat:", response);
      if (response) {
        console.log("we cahet: ", response);
        setIsGenerating(false);
      }
    },
    onError(error: any) {
      if (error) {
        console.log("error: ", error);
        setIsGenerating(false);
      }
    },
  });

the api call is not working
if i call the api endpoint through a custom function inside the onsubmut function it works and returns teh reponse but i want to make api call through the hook what might be the issue

4 Replies

RexOP
does this make a post request?
idk
you did not show us the whole code
useChat does not mean anything rn