Skip to content
Stylhero 0.6.2
React Native

Theme

Core

Feedback

Inputs

Navigation

Overlays

React Native / Feedback

ToastProvider

Put it once near the root (inside ThemeProvider), then call useToast().show().

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

Example

import { Button, ToastProvider, useToast } from "@stylhero/native";

const noop = () => {};

function SaveButton() {
  const toast = useToast();
  return (
    <Button onPress={() => toast.show({ message: "Build saved", tone: "success", action: { label: "Undo", onPress: noop } })}>
      Save build
    </Button>
  );
}

function ToastProviderExample() {
  // once, near the root of the app; any screen inside can call useToast()
  return (
    <ToastProvider bottomOffset={72}>
      <SaveButton />
    </ToastProvider>
  );
}

Props

PropTypeDefaultDescription
children required ReactNode -
bottomOffset number - Distance from the bottom edge, e.g. your safe-area inset plus a tab bar. Default 24.

Accessibility

  • Toasts are announced without taking focus. A toast with an action says the action is available ("Build saved. Undo available.").
  • While a screen reader is on, toasts with an action stay until closed, so there's time to reach the button.
  • The slide-in is skipped when Reduce Motion is on.

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