iamhosseindhv / notistack

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

Pass additional prop(s) using SnackbarProvider #571

Closed vlrmprjct closed 1 year ago

vlrmprjct commented 1 year ago

Hello,

my question is about passing additional props ( additionalProp ) using SnackbarProvider and a customized component. It is intended to add a global translation object for example.

In this simplifyed example below the additionalProp is not existing in the CustomSnack props:

<SnackbarProvider
    additionalProp="whatever"   // <=== This one is not present @ CustomSnack props
    className="whatever-class"  // <=== This one is present @ CustomSnack props
    Components={{
        success: CustomSnack,
    }
>
    {/* something more */}
</SnackbarProvider>

I tried this but this returns an error:

<SnackbarProvider
    className="whatever-class"
    Components={{
        success: (someProps) => <CustomSnack  { ...someProps } additionalProp="whatever" />,
    }
>
    {/* something more */}
</SnackbarProvider>

The error msg is: notistack - Custom snackbar is not refForwarding

image

Is there a way or workaround to add an additional prop ? Maybe I am doing something wrong. A hint would be great.

Thx.

iamhosseindhv commented 1 year ago

Hey @vlrmprjct - As described in the docs, one of the requirements for the custom component is to use React.forwardRef. This should fix the react error regarding ref.

As to passing custom props through SnackbarProvider, unfortunately it's not on the roadmap and won't be added any time soon. Sorry about that!