<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TomPradat</title>
    <description>The latest articles on DEV Community by TomPradat (@tompradat).</description>
    <link>https://dev.to/tompradat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F237044%2Fae620842-ac53-46bf-a833-56eed01f83a2.jpeg</url>
      <title>DEV Community: TomPradat</title>
      <link>https://dev.to/tompradat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tompradat"/>
    <language>en</language>
    <item>
      <title>React lib overriding your web app context</title>
      <dc:creator>TomPradat</dc:creator>
      <pubDate>Thu, 16 Jan 2020 20:14:31 +0000</pubDate>
      <link>https://dev.to/tompradat/react-lib-overriding-your-web-app-context-5a1i</link>
      <guid>https://dev.to/tompradat/react-lib-overriding-your-web-app-context-5a1i</guid>
      <description>&lt;p&gt;Hi, I was wondering about good patterns concerning the react context.&lt;/p&gt;

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

&lt;p&gt;I don't expect the &lt;code&gt;barLib&lt;/code&gt; to ever override my react-intl context, because i'm not aware it uses internally the &lt;code&gt;react-intl&lt;/code&gt; lib.&lt;br&gt;
But the &lt;code&gt;barLib&lt;/code&gt; can accidentally override the react-intl context =&amp;gt; &lt;a href="https://codesandbox.io/s/embedded-contexts-test-z8e7b"&gt;https://codesandbox.io/s/embedded-contexts-test-z8e7b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This kinda breaks the isolation of libs IMO.&lt;/p&gt;

&lt;p&gt;I see several solutions :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't use an other lib context in the &lt;code&gt;barLib&lt;/code&gt; (pretty extreme)&lt;/li&gt;
&lt;li&gt;Check that there is not already an intl context in the &lt;code&gt;barLib&lt;/code&gt;, if so merge the context values ?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm not convinced with either solutions, what do you guys think about it ?&lt;/p&gt;

&lt;p&gt;UPDATE :&lt;/p&gt;

&lt;p&gt;IMO the right way is to NEVER implement yourself a provider from a third-party library, you should just document your library so that users know they should wrap your components with the needed provider.&lt;/p&gt;

&lt;p&gt;Exemple : If you want to use &lt;code&gt;react-intl&lt;/code&gt;, just use it and tell people that your component must be wrapped into a react intl provider.&lt;/p&gt;

</description>
      <category>react</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
