Skip to content
Docs
Hooks
useToast

useToast

Hook to display a Toast component imported from react-native-toast-message library.

https://github.com/calintamas/react-native-toast-message (opens in a new tab)

Import

import { useToast } from 'react-native-ficus-ui';

Usage

const { show, hide } = useToast();
 
<Button
  onPress={() => {
    show({
      type: 'success',
      text1: 'Hello',
      text2: 'This is some something 👋',
    });
  }}
  colorScheme="green"
>
  Show Success
</Button>;

Update config on theme

toastProps: {
    position: 'bottom',
    config: {
        success: ({ text1, text2 }: BaseToastProps) => (
            <View>
                <Text>{text1}</Text>
                <Text>{text2}</Text>
            </View>
        ),
        error: ({ text1, text2 }: BaseToastProps) => (
            ...
        ),
        warning: ({ text1, text2 }: BaseToastProps) => (
            ...
        ),
        info: ({ text1, text2 }: BaseToastProps) => (
            ...
        ),
    },
},

Custom Toast config

You can edit all Toast props and Toast layout as you want by passing ToastProps to your theme as defined here :

https://github.com/calintamas/react-native-toast-message/blob/main/src/types/index.ts (opens in a new tab)

Pass ToastProps into toastProps object inside your Ficus UI theme.