Skip to content

How do I get my current store outside of a react / component context? #799

Answered by jmyrland
janniksam asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @janniksam !

Yes, this is possible. When you create your store instance (via createStore()) you can operate on this instance wherever you want to.

To access the state from the store instance, you have to call getState() and for actions getActions().

I've set up this sandbox to show a working example:

  1. The store is created & exported from store/index.ts
  2. The business.ts imports the store and exports a method to do some work.
  3. main.js calls upon the method from business.ts. This should log the current state & add a todo to the list.

Hope that helps 👍

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jmyrland
Comment options

You must be logged in to vote
1 reply
@jmyrland
Comment options

jmyrland Dec 3, 2022
Collaborator

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
2 participants