-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use in a monorepo with hooks packages wrapping the store #28
Comments
Hi. I will try to look during the week. |
Yes, seems like it is not a Nano Store issue but pnpm (in a way). Since we have a multiple packages with the store, we will have 2 different stores. It is hard to image what we can do with that on Nano Stores side. I suggest export |
Thanks for looking into this, Andrey. To avoid changing the store package, as it could be used directly for non-React app I think the hooks package could instead export an initialisation function that would accept the store as argument and enclose it for hooks. What do you think of this approach? |
I ended up exporting a binding function from the React hooks package that would then be bound with the store in the app. import { store } from '@monorepo/my-store';
import { bindStore } from '@monorepo/my-react-hooks';
export const { useCounter } = bindStore(store); |
I have encountered an issue in a monorepo setup. I created a package with nanostore that has some logic including subscriptions to the atoms. I created another package which wraps the store into custom React hooks that I would like to export as an API to access the store data. However, the consumer app loses the atom subscriptions when used via custom hooks. But it works when the custom hook is created in the consumer app.
Please see this minimal reproducible example repo.
pnpm install
andpnpm start
;The first button increments the count within React component but does nothing for the subscription outside. The second button updates the count in both React component and the subscription outside of React (browser console).
I assumed that the issue lies somewhere around the multiple version of the store being used but no matter what I tried with peer dependencies doesn't help.
The text was updated successfully, but these errors were encountered: