React: Question: react lib context overrides app context

Created on 16 Jan 2020  路  3Comments  路  Source: facebook/react

Hi, I believe that this can potentially be an issue, though I'm not sure.

I was wondering about good patterns concerning the react context.

Let's get a public library, for example react-intl that exposes a Provider (IntlProvider).
Let's create a library barLib that uses react-intl to manage translations internally and that also exposes a Provider.
Now let's imagine I create a web app and use both barLib and react-intl.

I don't expect the barLib to ever override my react-intl context, because i'm not aware it uses internally the react-intl lib.
But the barLib can accidentally override the react-intl context => https://codesandbox.io/s/embedded-contexts-test-z8e7b

This kinda breaks the isolation of libs IMO.

I see several solutions :

  • Don't use an other lib context in the barLib (pretty extreme)
  • Check that there is not already an intl context in the barLib, if so merge the context values ?

I'm not convinced with either solutions, what do you guys think about it ?

Invalid Question

All 3 comments

Support requests filed as GitHub issues often go unanswered. We want you to find the answer you're looking for, so we suggest the following alternatives:

Coding Questions

If you have a coding question related to React and React DOM, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.

https://stackoverflow.com/questions/tagged/react

Talk to other React developers

There are many online forums which are a great place for discussion about best practices and application architecture as well as the future of React.

https://reactjs.org/community/support.html

Check that there is not already an intl context in the barLib, if so merge the context values ?

Seems like you'd definitely want to merge values in this case, FWIW.

I'll try stackoverflow, thank you for your time :)

Was this page helpful?
0 / 5 - 0 ratings