calintamas / react-native-toast-message

Animated toast message component for React Native
MIT License
1.6k stars 252 forks source link

Custom Type not Showing #367

Open jjspscl opened 2 years ago

jjspscl commented 2 years ago

Describe the bug I have followed the setup instructions where I put a Toast instance in the end of the root component

# App.tsx
const App = () => {
    return (
        ...
        <QueryClientProvider client={queryClient}>
            <SafeAreaProvider>
            <View style={styles.container}>
                <MainRouter initialScene={initialScene} />
            </View>
            </SafeAreaProvider>
        </QueryClientProvider>
        <Toast config={toastConfig}/>
    )
}

# toast.config.tsx
const toastConfig: ToastConfig = {
    errorToast: (props) => (
        <ErrorToast
            { ...props }
            text2NumberOfLines={4}
            text2Style={{
                height: 50
            }}
        />
    )
}

When I call/show the toast in a Route/Component it shows the following error

Toast.show({
      type: 'errorToast',
      text1: 'Something went wrong',
      text2: apiErrorExtractor(error),
      visibilityTime: 6000
    });

image

Any help would be appreciated

Environment (please complete the following information):

rhfksl commented 1 year ago

I don't know why but it works when I set config file as v1.

const toastConfig = {
    InformationToast: InformationToast,
    ErrorToast: ErrorToast
};

it works, but it causes type error. I'm also struggling with that problem.

henrique-in commented 1 year ago

Where are you running Toast?

hendradedis commented 1 year ago

@henrique-in , if not show toast , you can try this on navigation container https://github.com/calintamas/react-native-toast-message/blob/2945e4a90e601bd4c02416e431c70414186b0e2b/docs/navigation-usage.md

samvoults commented 5 months ago

use error: (props) => { ... } instead of errorToast: (props) => ( ... }