react-native-styled-toast icon indicating copy to clipboard operation
react-native-styled-toast copied to clipboard

Trigger Toast outside of react component.

Open HridayK97 opened this issue 4 years ago • 2 comments

Is there a way to trigger the toast outside of the react component/jsx. I need a way to reference and trigger the toast in a redux action.

HridayK97 avatar Jan 21 '21 20:01 HridayK97

Yes it's possible. You have to register toast.

That work for me

<ToastContext.Consumer>
    {({toast})
        => {
        registerToast(toast);
        return (
            <>
                //Your code
            </>
        )
    }}
</ToastContext.Consumer>
export let toastFn: (options: ToastConfig) => void;

export function registerToast(fn: (options: ToastConfig) => void): void {
  toastFn = fn;
}

@HridayK97 That's what you meant?

feleko avatar Apr 08 '21 13:04 feleko

@feleko Thanks for your support, but for me this solution didn't help, because JSX is still necessary. There is a way to trigger toast on a simple function (without React Component), redux actions for example?

andrefangeloni avatar Jul 06 '22 01:07 andrefangeloni