Skip to content

Subscription usage #5

Answered by DawidWraga
devnaumov asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @devnaumov , thanks for your questions. I will improve the docs to make this clearer.

Is it okay to subscribe to certain state changes? For instance, if I have activeTodo: 1, I want to run some effect when activeTodo has changed, like this: todoStore.activeTodo.onChange(someLogic)

Yes, using todoStore.activeTodo.onChange(someLogic) is perfectly fine, assuming that activeTodo is state.

Currently, computed values don't have the onChange method, but I'll consider adding it in the future.

Does state automatically handle the unsubscribe logic?

If you are using createStoreContext, the Provider component automatically unsubscribes from all store effects when the component is unmounted.

I…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by devnaumov
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