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

SnackbarProvider overrode by an external lib #216

Closed TomPradat closed 4 years ago

TomPradat commented 4 years ago

Expected Behavior

I'd expect my app "notistack" context not to be overriden by an external lib

Current Behavior

The external lib uses notistack to dispatch some notifications, the props on their SnackbarProvider override mines.

Steps to Reproduce

The problem is exactly this one : https://stackoverflow.com/questions/59777098/react-lib-overriding-your-web-app-context. You can find a sandbox that reproduces it

Your Environment

Tech Version
Notistack 0.9.7
React 16.12
yoohahn commented 4 years ago

I fail to see this as a notistack issue. This is how React Context works. A Consumer uses the nearest Provider. In the example from the Code Sandbox The barLib/index.js is creating a new IntlProvider with new messages, and the {children} in that component will then use that Provider. And since the children is the Child component from App.js

// BarProvider const BarProvider = ({children}) => (<div><IntlProvider messages={{foo: "baz"}}>{children}</IntlProvider></div>)

<IntlProvider messages={{foo: "bar"}}>
  <Child />{/* <- Will print bar */}
  <BarProvider>
    <Child />{/* <- Will print baz */}
  </BarProvider>
</IntlProvider>

Is the same as doing

<IntlProvider messages={{foo: "bar"}}>
  <Child /> {/* <- Will print bar */}
  <div>
    <IntlProvider messages={{foo: "baz"}}>
        <Child /> {/* <- Will print baz */}
    </IntlProvider>
  </div>
</IntlProvider>

It more sound like an issue with the other library that you use. Why is it using a third party library and forces you to use that provider? You should put the bug on that library

TomPradat commented 4 years ago

I've though about this thoroughly and I agree with you about the fact that a library should not use a provider of an other lib. It should let the user implement it and document it