new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Core · all subjects

ui hooks - useobject

3 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

useObject hook parameters and return values

The useObject hook accepts parameters including api (endpoint URL) and schema (Zod schema). It returns an object containing: object (the streamed partial object), submit (function to start generation), isLoading (boolean for loading state), and stop (function to stop the stream).

Client-side streaming object generation example

```tsx 'use client'; import { useObject } from '@ai-sdk/react'; import { notificationSchema } from './api/use-object/schema'; export default function Page() { const { object, submit, isLoading, stop } = useObject({ api: '/api/use-object', schema: notificationSchema, }); return ( <div> <button onClick={() => submit('Messages during finals week.')} disabled={isLoading} > Generate notifications </button> {isLoading && ( <div> <div>Loading...</div> <button type="button" onClick={() => stop()}> Stop </button> </div> )} {object?.notifications?.map((notification, index) => ( <div key={index}> <p>{notification?.name}</p> <p>{notification?.message}</p> </div> ))} </div> ); } ``` This example shows how to use the useObject hook with loading state and stop functionality to stream and display structured object generation.

useObject partial object handling in JSX

When streaming objects with useObject, the object property contains partial data that arrives incrementally. JSX must handle undefined values for nested properties using optional chaining or conditional rendering. Use optional chaining to access properties at any level, for example: object?.notifications?.map(), notification?.name, and notification?.message.

Give your agent this brain