iamhosseindhv / notistack

Highly customizable notification snackbars (toasts) that can be stacked on top of each other
https://notistack.com
Other
3.93k stars 298 forks source link

Enqueue snackbar without hooks or HOC #159

Closed amirqasemi74 closed 5 years ago

amirqasemi74 commented 5 years ago

I need to enqueue snackbar without using hooks or hocs...

import { enqueueSnackbar } from 'notistack';

class UserViewModel {
  didMount(){
    try {
       ...
    }catch(e){
       enqueueSnackbar(e.message);
    }
  }
}

like react-toastify...

zhuangya commented 5 years ago

I think you are saying that you need to call enqueueSnackbar out of component scope?

It seems that we should expose this method?

amirqasemi74 commented 5 years ago

Exactly....

zhuangya commented 5 years ago

@amirqasemi74 I am also facing this problem. For now, I have to write a component returns null, and trigger the enqueueSnackbar on redux state change, like exactly what the official example did.

iamhosseindhv commented 5 years ago

have a look at the solution presented here: https://github.com/iamhosseindhv/notistack/issues/30

iamhosseindhv commented 5 years ago

Hopefully that has fixes your issue. closed due to inactivity.

amirqasemi74 commented 5 years ago

i think if you provide this solution inside your library as feature is better than every one who want to use it like me wrap your library in to it's own... it could be a cool feature...