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

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: 3 comments 5 replies

You must be logged in to vote
3 replies
@coltanium13

@dbritto-dev

Answer selected by coltanium13
@coltanium13

You must be logged in to vote
0 replies

You must be logged in to vote
2 replies
@dai-shi

@kenas4idps

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