I am creating my react app with material-ui Snackbar. In my project I have a lot of components and don't want to insert <Snackbar/> in each of them. Is there a way to create function that will show snackbar, then just import and use this function in each component?
Something like:
import showSnackbar from 'SnackbarUtils';
showSnackbar('Success message');
You have to do it in react way. You can achieve this by creating a Higher Order Component.
Check this out. https://stackblitz.com/edit/snackbar-hoc?file=src/SnackbarHOC.js