question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: is it possible to execute code "on state change"

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
krasimircommented, Feb 28, 2018

Yep. Thanks for the understanding. I just feel that a little bit of a anti-pattern.

0reactions
poteirardcommented, Feb 28, 2018

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found