Current Behavior
- Getting “Invalid hook call” error when using
useChat
hook from Vercel AI SDK - Error: “Cannot read property ‘useState’ of null”
- Hook is failing to initialize properly in the React Native environment
Expected Behavior
useChat
hook should properly initialize and provide chat functionality- Should work within React Native Expo component structure
Code Causing the Issue
const { messages, error, handleInputChange, input, handleSubmit } = useChat({
fetch: expoFetch as unknown as typeof globalThis.fetch,
api: generateAPIUrl(‘/api/chat’),
onError: (error) => console.error(error, ‘ERROR’),
});
Project Information
- Framework: React Native with Expo
- Using Vercel AI SDK for chat functionality
- File:
/home/rinz/Desktop/FutureU/RN/app/(app)/home.tsx
- Component Stack shows this is within a complex navigation structure using React Navigation
- Current ui / backend code is same as this guide Getting Started: Expo