DEV Community

Discussion on: The Easiest Way to Use Snackbars in Vue

Collapse
 
brettfishy profile image
Brett Fisher • Edited

Yeah, I actually thought about doing it this way at first but decided I didn't really want my snackbar's state to be stored in the global Vuex store. Of course, this is a matter of personal preference, but I tend to only store information in my store that pertains to the app as a whole (e.g. information about the logged-in user, the cache for network requests, etc.). A snackbar is so temporary that I didn't quite feel justified in storing its state in the store. I couldn't see myself needing to access that information globally across other components.

This article only talks about passing a message to be displayed by the snackbar, but there are a lot of other options that you might want to pass in too. See this npm package for example. If I wanted to support options like those, then I definitely wouldn't want that information hanging around in the global store.

I should add that I definitely don't think you should default to event buses for solving your Vue problems. As you can imagine, it can get pretty messy if you have components adding events to the bus all over your app. I think most problems can be solved with props or Vuex. I've been working with Vue for two years and this snackbar case is literally the only time when I've used an event bus and thought it made more sense than other alternatives.

Collapse
 
zolotarev profile image
Andrew Zolotarev

Thanks for reply.