# Question Freeform Example

> Example implementation of question freeform.

A shadcn/ui block from the [@ai-elements](https://ai-sdk.dev/elements) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/ai-elements/example-question-freeform).

- Page, with a live preview: https://shadcn.exchange/r/ai-elements/example-question-freeform
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/ai-elements/example-question-freeform-light-6b4956ca51cbcb1f.png
- Registry item: https://ai-sdk.dev/elements/api/registry/example-question-freeform.json
- Listed: 2026-10-14, source last changed 2026-10-14

## Install

```bash
npx shadcn@latest add https://ai-sdk.dev/elements/api/registry/example-question-freeform.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `https://elements.ai-sdk.dev/question.json`

## Files

### `registry/default/examples/question-freeform.tsx`

```tsx
"use client";

import type { QuestionResponse } from "@/components/ai-elements/question";

import {
  Question,
  QuestionActions,
  QuestionDescription,
  QuestionInput,
  QuestionPrompt,
  QuestionSubmit,
} from "@/components/ai-elements/question";
import { useCallback, useState } from "react";

const Example = () => {
  const [answer, setAnswer] = useState<string>();
  const handleSubmit = useCallback(({ text }: QuestionResponse) => {
    setAnswer(text);
  }, []);

  if (answer) {
    return (
      <div className="w-full max-w-2xl rounded-lg border bg-background p-4 text-sm">
        <span className="text-muted-foreground">Answered: </span>
        {answer}
      </div>
    );
  }

  return (
    <Question className="w-full max-w-2xl" onSubmit={handleSubmit}>
      <div className="space-y-1">
        <QuestionPrompt>What should we name the project?</QuestionPrompt>
        <QuestionDescription>
          Enter a short, memorable name.
        </QuestionDescription>
      </div>
      <QuestionInput aria-label="Project name" placeholder="Project name…" />
      <QuestionActions>
        <QuestionSubmit>Answer</QuestionSubmit>
      </QuestionActions>
    </Question>
  );
};

export default Example;
```
