Question: is it possible to execute code "on state change"
See original GitHub issueHi,
One question, is it possible to execute code before entering to specific state.
I have a state machine which every state has a transition like next
that execute some code (a http request) and then transition to the next state. However I want to check the state before actually reaching that state, let’s say to check if the state has X prop.
Is that possible without creating a transition like “checkingState”? Somehow like a specific callback? I saw that I can use middleware but I’m not sure if I can really achieve that like this.
Thank you 👍
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
How to run some code when state changes using onChange()
SwiftUI lets us attach an onChange() modifier to any view, which will run code of our choosing when some state changes in our...
Read more >How can I run an action when a state changes? - Stack Overflow
How do I run code (e.g print("Selection changed to \(selection)") when the $selection state changes? I looked through the docs and I couldn't ......
Read more >How can I run some code after changing state with React ...
is simple, you can go with useEffect . If you've got multiple items of state that need to be updated based on changes,...
Read more >Execute Code ONLY once on State change - Arduino Forum
I am trying to send a sms message 1 time (on state change?) when water is considered high or low(determined by 2 floating...
Read more >Hooks FAQ - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This page...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yep. Thanks for the understanding. I just feel that a little bit of a anti-pattern.
I think you are right. I just pointed out this because I used other state machine libraries in the past that offers those ‘hooks’ (Example: http://finite.readthedocs.io/en/master/examples/callbacks.html). But if you don’t want to include this functionality I totally understand it. Thanks for your help anyways 😃