New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@ai-sdk/react

Package Overview
Dependencies
Maintainers
3
Versions
1326
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/react

latest
Source
npmnpm
Version
4.0.157
Version published
Weekly downloads
4.1M
-30.05%
Maintainers
3
Weekly downloads
 
Created
Source

AI SDK: React provider

React UI components for the AI SDK:

Setup

npm i ai @ai-sdk/react

Usage

'use client';

import { useChat } from '@ai-sdk/react';
import { DefaultChatTransport } from 'ai';
import { useState } from 'react';

export default function Page() {
  const { messages, sendMessage, status } = useChat({
    transport: new DefaultChatTransport({
      api: '/api/chat',
    }),
  });
  const [input, setInput] = useState('');

  return (
    <>
      {messages.map(message => (
        <div key={message.id}>
          {message.role === 'user' ? 'User: ' : 'AI: '}
          {message.parts.map((part, index) =>
            part.type === 'text' ? <span key={index}>{part.text}</span> : null,
          )}
        </div>
      ))}

      <form
        onSubmit={e => {
          e.preventDefault();
          if (input.trim()) {
            sendMessage({ text: input });
            setInput('');
          }
        }}
      >
        <input
          value={input}
          onChange={e => setInput(e.target.value)}
          disabled={status !== 'ready'}
          placeholder="Say something..."
        />
        <button type="submit" disabled={status !== 'ready'}>
          Submit
        </button>
      </form>
    </>
  );
}

See the React documentation for more information.

Keywords

ai

FAQs

Package last updated on 24 Oct 2026

Related posts