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

multiple snackbars at once #14

Closed
ysgk opened this issue Oct 26, 2018 · 4 comments
Closed

multiple snackbars at once #14

ysgk opened this issue Oct 26, 2018 · 4 comments

Comments

@ysgk
Copy link

ysgk commented Oct 26, 2018

First, thanks for this project 😍

I want show multiple flash messages on page load, but I can't do that. (Maybe because notistack uses new Date().getTime() for its component's key prop?)

// This code shows only the last flash message.
componentDidMount() {
  const { enqueueSnackbar, flashes } = this.props
  flashes.forEach(flash => {
    enqueueSnackbar(flash.message)
  })
}

I found a workaround for this, but I think this is a little hacky.

componentDidMount() {
  const { enqueueSnackbar, flashes } = this.props
  setTimeout(() => {
    flashes.forEach(flash => {
     enqueueSnackbar(flash.message)
    })
  })
}

Do you have any plan to support such a case?

@iamhosseindhv
Copy link
Owner

iamhosseindhv commented Oct 26, 2018

Happy you like the project @ysgk ❤️

I'll investigate this to make sure new Date().getTime() is causing this behaviour, (and potentially use uid instead). But for now you may want to go with setTimeout.

flashes.forEach(item => {
    setTimeout(() => this.props.enqueueSnackbar(item), 1)
});

@iamhosseindhv
Copy link
Owner

#15 is on its way and will fix this issue.

so you'll be able to do something like:

componentDidMount = () => flashes.forEach(this.props.enqueueSnackbar);

@iamhosseindhv
Copy link
Owner

@ysgk this fix is available in the latest version.

@ysgk
Copy link
Author

ysgk commented Nov 27, 2018

Thank you for your kindness. It works fine now!

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