Inside your export const enqueueSnackbar = (notification) => {
function you have the notification
object, which has the options
and variant
that you can use:
export const enqueueSnackbar = (notification) => {
const key = notification.options && notification.options.key;
const variant = notification.options && notification.options.variant;
console.log(variant);
console.log(notification);
return {
type: ENQUEUE_SNACKBAR,
notification: {
...notification,
key: key || new Date().getTime() + Math.random(),
},
};
};
Update
Since you want to variant inside the SnackbarProvider
, you can pass the entire data (and not only the text-message) and use what you need inside.
export const enqueueSnackbar = notification => {
const key = notification.options && notification.options.key;
return {
type: ENQUEUE_SNACKBAR,
notification: {
message: { ...notification },
// ^ Instead of passing the text - I'm passing the entire object
key: key || new Date().getTime() + Math.random()
}
};
};
Inside the SnackbarProvider:
<SnackbarProvider
content={(key, notificationData) => {
const message = notificationData.message;
const variant = notificationData.options.variant
console.log(variant);
return <ToastTemplate id={key} message={message} />;
}}
>
Check here the working example: https://codesandbox.io/s/flamboyant-ramanujan-1p7yw?file=/index.js