'use client'; import { StreamableValue, useStreamableValue } from '@ai-sdk/rsc'; import { useState } from 'react'; import { generateNotifications } from './actions'; import { PartialNotification } from './schema'; // Allow streaming responses up to 30 seconds export const maxDuration = 30; // page component with a button to generate notifications export default function Page() { const [notificationStream, setNotificationStream] = useState | null>(null); return (
{notificationStream && ( )}
); } // separate component to display notifications that received the streamable value: function NotificationsView({ notificationStream, }: { notificationStream: StreamableValue; }) { const [data, pending, error] = useStreamableValue(notificationStream); return (
{data?.notifications?.map((notification, index) => (

{notification?.name}

{notification?.minutesAgo} {notification?.minutesAgo != null ? ' minutes ago' : ''}

{notification?.message}

))}
); }