Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger Toast outside of react component. #54

Open
HridayK97 opened this issue Jan 21, 2021 · 2 comments
Open

Trigger Toast outside of react component. #54

HridayK97 opened this issue Jan 21, 2021 · 2 comments

Comments

@HridayK97
Copy link

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.

@feleko
Copy link
Contributor

feleko commented Apr 8, 2021

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?

@andrefangeloni
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants