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

Feature request: option to bypass maxSnack #581

Open
simon-abbott opened this issue Sep 19, 2023 · 2 comments
Open

Feature request: option to bypass maxSnack #581

simon-abbott opened this issue Sep 19, 2023 · 2 comments

Comments

@simon-abbott
Copy link

This project is awesome, and has saved me a ton of time setting up notifications in a webapp I'm working on, but there's one small quirk I noticed. I set up an "is the browser offline" listener that displays a persistent alert if the answer is yes. It works great, but it eats up one of the maxSnack slots even though I'm setting it to persistent and displaying it with a different anchor origin. It would be great if there was a way to tell enqueueSnackbar "hey, don't count this one towards the limit". I don't think it's likely to be an actual problem in practice since we're usually only going to have one normal alert at a time anyway, but it still seems like a missing feature from this otherwise amazingly customizable package.

@simon-abbott
Copy link
Author

Possible duplicate of #557. Didn't search well enough before hitting submit I guess.

@iamhosseindhv
Copy link
Owner

iamhosseindhv commented Sep 19, 2023

@simon-abbott Each SnackbarProvider enforces its own maxSnack limit. So depending on your requirements, you might be able to simply use 2 SnackbarProviders, one* dedicated to "browser offline listener", the other dedicated to other types of notifications.

If you do this, make sure you show snackbars by using enqueueSnackbar from useSnackbar.

// don't do
import { enqueueSnackbar } from 'notistack'

// instead do
import { useSnackbar } from 'notistack'
const MyComponent = () => {
   const { enqueueSnackbar } = useSnackbar()
   // ... 
}

P.S: This workaround works better if your "browser offline listener" snackbars are positioned differently from other types of snackbars. For example, use bottom-center as anchorOrigin for these notifications, and stick to bottom-left for other types of notifications.

Either way I understand non of these are ideal, but thought I'd share :)

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

2 participants