New Sep 9, 2025

Sharing context across apps/packages in Turborepo

Libraries, Frameworks, etc. All from Newest questions tagged reactjs - Stack Overflow View Sharing context across apps/packages in Turborepo on stackoverflow.com

My turborepo has several packages, one of which is a ui library that uses some context providers. I export these context providers (Theme, Toast, etc.) so that I can use my UI components in my apps and other packages.

I have set peerdependencies on all packages, enforced strict versioning, and in my root package.json created pnpm overrides, and added a public hoist pattern.

No matter what happens, I get the same problem - useTheme must be used within a ThemeProvider.

This I believed was because when we have different react versions being loaded, the package might create a different instance. Can this be managed, or is the only solution to have providers created in each package?

Scroll to top