Skip to content

Store is returned as undefined #1748

Answered by YuanRuQian
sankomil asked this question in Q&A
Discussion options

You must be logged in to vote

I've tried to create a demo according to your description: https://codesandbox.io/s/1748-r8dkq?file=/src/models/UseStores.ts

I think the culprit is this line:

const RootStoreContext = createContext<RootStore>({} as RootStore);

You just asserted the type to fool the typing system

But you need to actually create an instance for RootStore here!

PS You can play with this part in the demo to compare different console output results with / without an actual instance

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sankomil
Comment options

@YuanRuQian
Comment options

@sankomil
Comment options

Answer selected by sankomil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants