Skip to content
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

Best way to combine stores in multiple files #228

Closed
sepehr500 opened this issue Nov 3, 2020 · 7 comments
Closed

Best way to combine stores in multiple files #228

sepehr500 opened this issue Nov 3, 2020 · 7 comments

Comments

@sepehr500
Copy link

Does anybody have a good way of combining multiple smaller stores in multiple files into a single store?

@dai-shi
Copy link
Member

dai-shi commented Nov 3, 2020

You can combine multiple store creators into a single one to create a store.

import createStoreA from '...'
import createStoreB from '...'

const useStore = create((set, get, api) => ({
  ...createStoreA(set, get, api),
  ...createStoreB(set, get, api),
}))

Disclaimer: I didn't test it.

@sepehr500
Copy link
Author

Nice! Any idea how the types would work?

@dai-shi
Copy link
Member

dai-shi commented Nov 3, 2020

Good question. I'd expect it would work with type annotation, but not sure if type inference would work. Please give it a try.

@sepehr500
Copy link
Author

It works! thanks.

@victorwpbastos
Copy link

It works! thanks.

How did you make it work with types?

@FlorianGoussin
Copy link

FlorianGoussin commented Jun 10, 2023

Hello, I know this issue is closed, but I tried to follow the solution that seems to work for sepehr500 and I ended up with some errors. I started a thread on stackoverflow:
https://stackoverflow.com/questions/76444458/combine-two-stores-with-react-and-zustang
Could someone help me with that?

@dbritto-dev
Copy link
Collaborator

dbritto-dev commented Jun 10, 2023

Hello, I know this issue is closed, but I tried to follow the solution that seems to work for sepehr500 and I ended up with some errors. I started a thread on stackoverflow:
https://stackoverflow.com/questions/76444458/combine-two-stores-with-react-and-zustang
Could someone help me with that?

@FlorianGoussin please create a discussion so I can help you on that thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants