Skip to content

Can you call useStore outside of a functional component or custom hook? Like in a test or helper function #1986

Closed Answered by dbritto-dev
coltanium13 asked this question in Q&A
Discussion options

You must be logged in to vote

@coltanium13 yes, you can use any hook created by create() function outside of react, you can use getState() and/or setState() but setState() doesn't trigger a new render which is useful for testing but if you want to listen any changes on the store you need to use subscribe()

Replies: 2 comments 3 replies

Comment options

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

@dbritto-dev
Comment options

Answer selected by coltanium13
@coltanium13
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants