# AssistantIf
URL: /docs/api-reference/primitives/assistant-if
Conditional rendering component based on thread, message, or composer state.
***
title: AssistantIf
description: Conditional rendering component based on thread, message, or composer state.
-----------------------------------------------------------------------------------------
Conditionally render children based on assistant state.
import { ParametersTable } from "@/components/docs/tables/ParametersTable";
## Anatomy
```tsx
import { AssistantIf } from "@assistant-ui/react";
thread.isEmpty}>
```
## Overview
`AssistantIf` is a generic conditional rendering component that provides access to the full assistant state. It replaces the deprecated `ThreadPrimitive.If`, `MessagePrimitive.If`, and `ComposerPrimitive.If` components with a single, flexible API.
## API Reference
boolean",
required: true,
description: "A function that receives the assistant state and returns whether to render children.",
},
{
name: "children",
type: "ReactNode",
description: "Content to render when the condition returns true.",
},
]}
/>
## AssistantState
The condition function receives an `AssistantState` object with the following properties:
## Examples
### Thread State Conditions
```tsx
// Show welcome screen when thread is empty
thread.isEmpty}>
// Show loading indicator while running
thread.isRunning}>
// Conditional send/cancel button
!thread.isRunning}>
Send
thread.isRunning}>
Cancel
```
### Message State Conditions
```tsx
// Show avatar only for assistant messages
message.role === "assistant"}>
// Show disclaimer on last message
message.isLast}>
// Toggle copy icon based on copied state
!message.isCopied}>
message.isCopied}>
// Show speak/stop button based on speech state
message.speech == null}>
message.speech != null}>
```
### Composer State Conditions
```tsx
// Show placeholder when composer is empty
composer.isEmpty}>
// Show attachment preview when editing
composer.isEditing}>
```
### Complex Conditions
```tsx
// Combine multiple conditions
!thread.isRunning && message.role === "assistant"
}>
// Custom logic
thread.messages.length > 0 && !thread.isRunning
}>
```
## Type Export
You can import the `AssistantIf.Condition` type for typing your condition functions:
```tsx
import { AssistantIf } from "@assistant-ui/react";
const isThreadEmpty: AssistantIf.Condition = ({ thread }) => thread.isEmpty;
```
## Migration from Deprecated Components
`ThreadPrimitive.If`, `MessagePrimitive.If`, and `ComposerPrimitive.If` are deprecated. Use `AssistantIf` instead.
| Before | After |
| -------------------------------------- | ------------------------------------------------------------------------- |
| `` | ` thread.isEmpty}>` |
| `` | ` thread.isRunning}>` |
| `` | ` !thread.isRunning}>` |
| `` | ` message.role === "user"}>` |
| `` | ` message.role === "assistant"}>` |
| `` | ` message.isCopied}>` |
| `` | ` message.speech != null}>` |
| `` | ` message.isLast}>` |
| `` | ` composer.isEditing}>` |