# Stateful Button — React Native component for Expo

> Button whose label rolls and width springs through loading, success and error.

A button that walks through idle, loading, success and error: the label rolls letter by letter to the next text while the width springs to fit it. A spinner, a self-drawing check or a shaking cross grows in beside the label, and it drives itself when onPress returns a Promise.

- Docs: https://expokit.in/docs/components/stateful-button
- Tier: Free
- Also called: loading button, async button, submit button with spinner
- Category: Buttons
- Platforms: iOS, Android, web
- Expo Go: yes, no development build needed
- npm dependencies: react-native-svg, expo-haptics
- Uses ExpoKit items: kit
- Variants: Save Changes, Payment Retry, Controlled, Variants And Sizes, Follow Toggle

## Installation

Run once per project: `npx @expokit/cli@latest init` (shared theme + KitProvider). Then:

```bash
npx @expokit/cli@latest add stateful-button
```

The CLI copies the source into your project (you own the code) and installs react-native-svg, expo-haptics.

Import: `import { StatefulButton } from "@/components/ui/stateful-button";`

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `string` | — | Label while idle. |
| `state` | `"idle" \| "loading" \| "success" \| "error"` | — | Controlled state. Omit it to let a Promise from onPress drive the button. |
| `onPress` | `() => void \| Promise<unknown>` | — | Resolve → success, reject → error, then back to idle (when state is not set). |
| `loadingText` | `string` | `children` | Label while loading. |
| `successText` | `string` | `labels.done` | Label after success. |
| `errorText` | `string` | `labels.failed` | Label after an error. |
| `variant` | `"primary" \| "secondary" \| "outline" \| "ghost"` | `"primary"` | Idle look; success and error tint it green / red. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | 36 / 46 / 54pt tall. |
| `color` | `string` | `theme primary` | Tint for the idle look. |
| `resetAfter` | `number` | `1600` | ms the result shows before returning to idle (self-driving only). |
| `minLoading` | `number` | `500` | Minimum ms of spinner (self-driving only). |
| `onStateChange` | `(state) => void` | — | Called on every state change. |
| `pill` | `boolean` | `false` | Fully rounded ends. |
| `block` | `boolean` | `false` | Stretch to the parent's width (no width animation). |
| `disabled` | `boolean` | `false` | Blocks presses and dims the button. |
| `haptics` | `boolean` | `true` | Taps on press, success and error. |
| `accessibilityLabel` | `string` | `current label` | Override what screen readers hear. |
| `textStyle` | `StyleProp<TextStyle>` | — | Style for the label letters. |
| `style` | `StyleProp<ViewStyle>` | — | Style for the outer wrapper (margins, alignment). |
| `className` | `string` | — | Tailwind classes on the root when using NativeWind or Uniwind. Prefer style for StyleSheet overrides. |

## Behaviour & accessibility

- **Touch**: Springs to 96% on press; at least 44pt tall to touch (hitSlop on the small size). Presses are ignored while loading and, when self-driving, until it returns to idle.
- **Motion**: Label letters roll on the native driver; width, colour and the check / cross stroke spring or ease on the JS driver on separate views.
- **Reduced motion**: Labels crossfade instead of rolling and the width changes instantly.
- **Haptics**: Light tap on press, success / error notification on the result (expo-haptics; turn off with haptics={false}).
- **Screen readers**: Button role with busy and disabled state; every new label (Saving…, Saved, Failed) is announced.
- **Platforms**: iOS, Android and web.

## FAQ

### How do I make a loading button in React Native?

Use ExpoKit's Stateful Button: run npx @expokit/cli@latest add stateful-button in your Expo or React Native project and it copies a ready-made loading button into your app as plain TypeScript you can edit. It works on iOS, Android and web, and in Expo Go.

### Does Stateful Button work in Expo Go?

Yes. Stateful Button runs in Expo Go on iOS and Android with no development build — its packages (react-native-svg, expo-haptics) are all included in Expo Go.

### How do I add Stateful Button to my Expo app?

Run npx @expokit/cli@latest add stateful-button in your project. The CLI copies the component's source into your app and installs react-native-svg, expo-haptics, so the code is yours to change.

### Is Stateful Button free?

Yes. Stateful Button is free: its full source is on this page and the CLI installs it without an account.

### Can I change how Stateful Button looks?

Yes. It takes its colours, radius and light / dark mode from useKit(), so wrapping your app in <KitProvider accent radius> re-skins it with every other ExpoKit component. The code lives in your project, so you can also edit anything directly.

## More

- Live preview, variants and code: https://expokit.in/docs/components/stateful-button
- Every ExpoKit component, screen, template and chart: https://expokit.in/llms.txt
- Install commands and props for every free component: https://expokit.in/llms-full.txt
- Pricing: https://expokit.in/pricing
