Closed VincentLanglet closed 5 years ago
@VincentLanglet notistack is not designed to work outside the component code. In my projects I tend to use something like the following:
fetchApi(url, method, payload)
.then(() => {
// ... enqueue snackbar
// ... redirect to /dashboard page
})
.catch((err) => this.props.enqueueSnackbar(err, { variant: 'error' } ))
Or dispatch a enqueue
action from Saga (if I'm using redux).
But there're other solutions presented here: #30 Namely this one: https://github.com/iamhosseindhv/notistack/issues/30#issuecomment-455822993
Hope this was useful.
Hey @iamhosseindhv, I also have this use case (specifically from an API polling service and a PouchDB changes service). I've looked at #30's workaround, and it should work for me, but it would be great if there was a direct method.
If it's something that could go on the roadmap that would be amazing. Either way, thank you for your work on this library.
I agree it'd be nice to have support for it.
Any implementation suggestion is welcome.
I use Apollo with an error link written this way:
Is it possible to replace
console.error
by something likeenqueueSnackbar
?