Official @xstate/react Console Logger function during Development/Debugging #2024
Unanswered
milanbgd011
asked this question in
Ideas
Replies: 1 comment 2 replies
-
I think we are sort of in a need to create an XState browser extension - enabling console.logs could be a checkbox there. WDYT? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I know you can track machine in Vizualizer and Redux Dev tools, this fits perfectly for some scenarios.
BUT, I am used to console.log as the best way to debug stuff, so I created a simple hook that I use in my apps when developing machine and it does wonders for me. All is JSON.stringified, so that I do no need to "expand" anything, just scroll thru the log.:
useXstateDebugger.ts
useXstateDebuggerActor.ts
Example output for simple event
What do you get from this?
Why?
Because when you are developing complex machines that goes thru a lot of invokes quickly, all other solutions are simply not enought to see the full picture. When I debug something, I get to the state which is good, then I open Console and clear out, then I "click button" or whatever, then scroll to the top of the console log and read step by step what is being performed, with what events and what was the context for each step. It logs perfectly events being fired by user input and by invoke functions. Debugging is flawless with this, you have exact transcript of everything in the console, just remember to "clear out" console before clicking a button or whatever, so that you can scroll to top and read entire log from the exact point where you cleared console from.
What I would like to see?
Beta Was this translation helpful? Give feedback.
All reactions