Skip to content
Stylhero 0.6.2
React Native

Theme

Core

Feedback

Inputs

Navigation

Overlays

React Native / Feedback

Alert

Inline message about the screen or the last action.

import { Alert } from "@stylhero/native";

Example

import { useState } from "react";
import { Alert } from "@stylhero/native";

function AlertExample() {
  const [open, setOpen] = useState(true);
  return open ? (
    <Alert tone="warning" title="Price changed" onDismiss={() => setOpen(false)}>
      The RTX 4070 Super is $40 more than when you saved this build.
    </Alert>
  ) : null;
}

Props

PropTypeDefaultDescription
action ReactNode - Buttons under the message, e.g. "Retry".
announce boolean false Read the alert out as soon as it appears (Android live region, iOS announcement). Use it for alerts caused by something the user just did, like a failed save; leave it off for messages that are part of the page.
children ReactNode - The message. A string is styled for you; pass elements for richer content.
dismissLabel string "Dismiss"
icon ReactNode - Icon before the text, e.g. a lucide-react-native icon.
onDismiss () => void - Shows a close button.
style StyleProp<ViewStyle> -
title string -
tone AlertTone "info"

Also takes React Native's View props (testID, accessibilityHint, onLayout…), passed to that View.

Types

type AlertTone = "info" | "success" | "warning" | "danger";

Accessibility

  • With announce it's read out when it appears: an alert with a polite live region on Android, an announcement on iOS. Use it for messages that appear after an action.
  • The icon is hidden; the dismiss button is labelled by dismissLabel ("Dismiss").

Generated from src/components/Alert.tsx. Something wrong or missing? Open an issue.