Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

How to consume same React context coming from different packages?

$
0
0

How to consume same React context coming from different packages?

E.g. I have package A which depends on common and common deps on ui-lib, and packageA deps on ui-lib.

In ui-lib there is an export const context = React.createContext({..}) and in package A and in common it will be different instances of the same context (because of different packages during the build).

I have few options now but they all.. not so good:

Solution A: re-export all the stuff from ui-lib in common, and in packageA import only from common

Solution B: use two context Providers in package A (one from ui-lib and one from common)

More context:

  1. I'm using npm without package locks
  2. I need this working while package A and common builds separately on CI
  3. package A and common is inside monorepo and ui-lib is external package, so we have in our repo:
— packages
—— packageA (deps on `common` from same monorepo and `ui-lib` )
—— common (deps on `ui-lib`)

What could I do?


Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images