Collapsible "thinking" block for one reasoning run of an assistant message.
Collapsible "thinking" block for one reasoning run of an assistant message.
import { Reasoning } from 'heroui-native-pro';<Reasoning>
<Reasoning.Trigger>
<Reasoning.Loader />
<Reasoning.Label>
<Reasoning.Duration />
</Reasoning.Label>
<Reasoning.Indicator />
</Reasoning.Trigger>
<Reasoning.Content>
<Reasoning.Text>...</Reasoning.Text>
</Reasoning.Content>
</Reasoning>status, and the duration. Also available as Reasoning.Root.Loader (grid, sm) shown while streaming. It fades out while its slot closes, so the label slides back instead of jumping.duration, in the foreground color, used inside the default label.The default trigger renders the loader, the label, and the chevron.
<Reasoning duration="9s">
<Reasoning.Trigger />
<Reasoning.Content>
<Reasoning.Text>{reasoningText}</Reasoning.Text>
</Reasoning.Content>
</Reasoning>Drive status from your AI SDK. While streaming, the trigger shows the loader and "Thinking". The block opens when the first content streams in (autoExpand) and collapses collapseDelay ms after the run completes, unless the user toggled it.
<Reasoning
status={isStreaming ? 'streaming' : 'complete'}
duration={isStreaming ? undefined : '12s'}
>
<Reasoning.Trigger />
<Reasoning.Content>
<Reasoning.Text>{reasoningText}</Reasoning.Text>
</Reasoning.Content>
</Reasoning>stopped and error keep the trace open, and a ChainOfThought inside shows its unfinished step as interrupted.
<Reasoning status="stopped" duration="4s">...</Reasoning>
<Reasoning status="error">...</Reasoning>A ChainOfThought inside the content takes its status from the root, so one variable drives both.
<Reasoning status={status}>
<Reasoning.Trigger />
<Reasoning.Content>
<ChainOfThought>
<ChainOfThought.Step status="complete">
<ChainOfThought.StepTitle>Searched the web</ChainOfThought.StepTitle>
</ChainOfThought.Step>
<ChainOfThought.Step status="active">
<ChainOfThought.StepTitle>Comparing results</ChainOfThought.StepTitle>
</ChainOfThought.Step>
</ChainOfThought>
</Reasoning.Content>
</Reasoning>A function child of Reasoning.Label receives defaultChildren, duration, isStreaming, and status. Use it to localize the label.
<Reasoning.Trigger>
<Reasoning.Loader />
<Reasoning.Label>
{({ status, defaultChildren }) =>
status === 'complete' ? (
<>
Réfléchi pendant <Reasoning.Duration />
</>
) : (
defaultChildren
)
}
</Reasoning.Label>
<Reasoning.Indicator />
</Reasoning.Trigger>Reasoning.Loader takes every Loader prop.
<Reasoning.Trigger>
<Reasoning.Loader variant="sparkle" color="warning" />
<Reasoning.Label />
<Reasoning.Indicator />
</Reasoning.Trigger>Automatic opening and collapsing call onExpandedChange too.
const [isExpanded, setIsExpanded] = useState(false);
<Reasoning isExpanded={isExpanded} onExpandedChange={setIsExpanded}>
...
</Reasoning>Rows of ChatConversation.Content unmount while scrolled out of view. Give each block a stateKey, unique within its message, to keep its expanded state.
<Reasoning stateKey={`reasoning-${index}`} status={status}>
...
</Reasoning>Layout transitions only animate the views that carry them. Wrap content laid out after the block in an Animated.View with layout={ReasoningLayoutTransition} so it moves in sync.
import { Reasoning, ReasoningLayoutTransition } from 'heroui-native-pro';
import Animated from 'react-native-reanimated';
<Reasoning status={status}>...</Reasoning>
<Animated.View layout={ReasoningLayoutTransition}>
...
</Animated.View>useReasoning() returns the root state. Use it to build your own trigger inside a Reasoning.
function MyTrigger() {
const { isExpanded, isStreaming, setIsExpanded } = useReasoning();
return (
<Pressable onPress={() => setIsExpanded(!isExpanded)}>
<Text>{isStreaming ? 'Thinking' : 'Show reasoning'}</Text>
</Pressable>
);
}
<Reasoning status={status}>
<MyTrigger />
<Reasoning.Content>...</Reasoning.Content>
</Reasoning>import { Button } from 'heroui-native';
import { Reasoning } from 'heroui-native-pro';
import { useEffect, useState } from 'react';
import { View } from 'react-native';
const WORD_DELAY = 70;
const WORDS =
'Let me compare the two plans. The annual plan costs less per month, but it locks the team in for a year. The monthly plan is more flexible while the team is still growing, so I will recommend starting monthly and switching once headcount settles.'.split(
' '
);
export default function ReasoningExample() {
const [wordCount, setWordCount] = useState(0);
const [runId, setRunId] = useState(0);
const isStreaming = wordCount < WORDS.length;
useEffect(() => {
if (!isStreaming) return;
const timeout = setTimeout(
() => setWordCount((count) => count + 1),
wordCount === 0 ? 1200 : WORD_DELAY
);
return () => clearTimeout(timeout);
}, [isStreaming, wordCount, runId]);
const handleRestart = () => {
setWordCount(0);
setRunId((id) => id + 1);
};
return (
<View className="flex-1 px-5 items-center justify-center">
<View className="w-full gap-8">
<View className="min-h-64">
<Reasoning
key={runId}
status={isStreaming ? 'streaming' : 'complete'}
duration={isStreaming ? undefined : '6s'}
>
<Reasoning.Trigger />
<Reasoning.Content>
<Reasoning.Text>
{WORDS.slice(0, wordCount).join(' ')}
</Reasoning.Text>
</Reasoning.Content>
</Reasoning>
</View>
<Button
variant="secondary"
size="sm"
className="self-center"
isDisabled={isStreaming}
onPress={handleRestart}
>
<Button.Label>Restart</Button.Label>
</Button>
</View>
</View>
);
}| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Trigger and content |
status | ReasoningStatus | 'complete' | Status of this block's run, not of the whole chat |
duration | string | - | Formatted thinking time, such as "9s", shown once complete or stopped |
autoExpand | boolean | true | Opens the trace when the first content streams in |
collapseDelay | number | 1000 | Milliseconds before collapsing after completion; Infinity keeps it open. Negative values use the default |
isExpanded | boolean | - | Controlled expanded state |
defaultExpanded | boolean | false | Expanded state on mount |
isDisabled | boolean | false | Disables the trigger. The content keeps its current state |
stateKey | string | - | Keeps the uncontrolled expanded state when a conversation row remounts |
className | string | - | Additional CSS classes for the root column |
onExpandedChange | (isExpanded: boolean) => void | - | Called when the expanded state changes, by the user or automatically |
animation | ReasoningRootAnimation | - | Animation configuration |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| value | description |
|---|---|
'streaming' | Shows the loader and the shimmering label |
'complete' | Shows "Thought for {duration}" and collapses after collapseDelay |
'stopped' | Keeps the trace open and marks an unfinished ChainOfThought step as interrupted |
'error' | Keeps the trace open and marks an unfinished ChainOfThought step as interrupted |
Animation configuration for the root. Can be:
true or undefined: default layout transitionfalse or "disabled": no layout transition (the panel height snaps); the chevron, the panel fade, and the loader keep animating"disable-all": disable all animations, including the chevron, the panel fade, the label fade, the loader, and the label shimmerobject: custom layout transition| prop | type | default | description |
|---|---|---|---|
state | 'disabled' | 'disable-all' | boolean | - | Disable animations while customizing properties |
layout.value | LayoutTransition | LinearTransition.springify().damping(140).stiffness(1600).mass(4) | Layout transition of the root and the content wrapper. Exported as ReasoningLayoutTransition |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Custom composition of the trigger parts |
className | string | - | Additional CSS classes for the row |
style | ViewStyle | - | Inline style of the row |
onPress | (event: GestureResponderEvent) => void | - | Called when pressed, before the content toggles |
...PressableProps | Omit<PressableProps, 'children' | 'style' | 'disabled'> | - | Other Pressable props. Disabled state comes from the root isDisabled |
| prop | type | default | description |
|---|---|---|---|
variant | LoaderVariant | 'grid' | Loader variant |
size | LoaderSize | number | 'sm' | Loader size |
...LoaderRootProps | LoaderRootProps | - | All Loader props are supported |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | ((props: ReasoningLabelRenderProps) => ReactNode) | - | Replaces the default text. A function can return defaultChildren |
className | string | - | Additional CSS classes for the label text |
animation | ReasoningLabelAnimation | - | Fade played on a status change |
...TextProps | Omit<TextProps, 'children'> | - | All standard React Native Text props are supported |
| prop | type | description |
|---|---|---|
defaultChildren | ReactNode | What the label shows by default for the status |
duration | string | The root duration |
isStreaming | boolean | Whether the run is streaming |
status | ReasoningStatus | The root status |
Animation configuration of the label. The label never fades in on mount. Can be:
true or undefined: the new label fades in when the status changesfalse or "disabled": the label swaps instantlyobject: custom fade| prop | type | default | description |
|---|---|---|---|
state | 'disabled' | boolean | - | Disable animations while customizing properties |
entering.value | EntryOrExitLayoutType | FadeIn.duration(150).easing(Easing.bezier(0.22, 1, 0.36, 1)) | Entering animation after a status change |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Replaces the root duration |
className | string | - | Additional CSS classes for the duration text |
...TextProps | TextProps | - | All standard React Native Text props are supported |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Replaces the default chevron |
className | string | - | Additional CSS classes. The rotation cannot be set via className |
iconProps | ReasoningIndicatorIconProps | - | Props of the default chevron |
animation | ReasoningIndicatorAnimation | - | Rotation configuration |
isAnimatedStyleActive | boolean | true | When false, the rotation is not applied, so you can style it via style |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
| prop | type | default | description |
|---|---|---|---|
size | number | 14 | Size of the chevron, in pixels |
color | string | theme muted (foreground while pressed) | Color of the chevron |
Animation configuration of the chevron. Can be:
true or undefined: default rotationfalse or "disabled": the chevron snaps between its rotationsobject: custom rotation| prop | type | default | description |
|---|---|---|---|
state | 'disabled' | boolean | - | Disable animations while customizing properties |
rotation.value | [number, number] | [0, -180] | Rotation values [collapsed, expanded] in degrees |
rotation.springConfig | WithSpringConfig | { damping: 140, stiffness: 1000, mass: 4 } | Spring configuration of the rotation |
The block auto-expands once the content has visible children: non-blank text, a Reasoning.Text with words, a ChainOfThought with a step, or any other element.
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Expanded content. String and number children are wrapped in a Reasoning.Text |
className | string | - | Additional CSS classes for the container |
classNames | ElementSlots<ContentSlots> | - | Additional CSS classes for the slots |
styles | Partial<Record<ContentSlots, ViewStyle>> | - | Inline styles for the slots |
animation | ReasoningContentAnimation | - | Entering / exiting animations of the panel |
...ViewProps | ViewProps | - | All standard React Native View props are supported |
ElementSlots<ContentSlots>| prop | type | description |
|---|---|---|
container | string | Always-mounted clipping wrapper whose height animates |
body | string | Panel mounted only while expanded, which fades in and out |
styles| prop | type | description |
|---|---|---|
container | ViewStyle | Clipping wrapper |
body | ViewStyle | Expanded panel |
Animation configuration of the panel. Can be:
true or undefined: default fade in / fade outfalse or "disabled": the panel appears and disappears instantlyobject: custom entering / exiting animations| prop | type | default | description |
|---|---|---|---|
state | 'disabled' | boolean | - | Disable animations while customizing properties |
entering.value | EntryOrExitLayoutType | FadeIn.duration(200).easing(Easing.bezier(0, 0, 0.2, 1)) | Entering animation of the panel |
exiting.value | EntryOrExitLayoutType | FadeOut.duration(200).easing(Easing.in(Easing.ease)) | Exiting animation of the panel |
| prop | type | default | description |
|---|---|---|---|
children | ReactNode | - | Reasoning text. Blank text renders nothing |
className | string | - | Additional CSS classes for the text |
...TextProps | TextProps | - | All standard React Native Text props are supported |
Returns the root state for building a custom trigger. Throws when used outside a Reasoning.
| property | type | description |
|---|---|---|
status | ReasoningStatus | Status of the run |
isStreaming | boolean | Whether the run is streaming |
duration | string | undefined | Formatted thinking time |
isExpanded | boolean | Whether the content is expanded |
isDisabled | boolean | Whether the trigger is disabled |
setIsExpanded | (isExpanded: boolean) => void | Expands or collapses the content, as a user toggle would |