Add documentation on starting the machine
See original GitHub issueTook me a while to realize that calling useMachine does not start the machine. Is there a good reason to leave that up to the caller? The machine is stopped when unmounting, so maybe it makes sense to start it when it is first called? If not, then it would be nice to document this. FWIW, I had to add this code to start my machine:
const machine = useMachine(...);
useEffect(() => {
machine.service.start();
}, []);
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
5 Steps to Create Technical Documentation That's (Actually ...
So if you don't know where to start, here's our short guide to making technical documentation that's actually helpful.
Read more >How to Write a Good Documentation: Home
Best Practices for Documenting Your Project · Include a README file that contains · Allow issue tracker for others · Write an API...
Read more >How to Build the Best User Documentation (New Guide) | Blog
Have a product or service that needs user documentation? Here are some simple tips on how to build the best documentation for consumers....
Read more >The importance of machine documentation
"Mastering the Machine" describes the process of concepting, procuring, designing, building and documenting a machine or system from the ...
Read more >How to Manage all Your Equipment Documentation | GoCodes
Try these tips to establish a winning equipment documentation management system, keep your business compliant, and your equipment in top condition.
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 FreeTop 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
Top GitHub Comments
I found the issue.
onTransition
andonChange
are called afterinit
, so anything that happens during initialization is missed. Callinginit
after both callbacks are set fixes the problem.I created a minimal example, but this may actually be an issue with xstate, it looks like it isn’t calling
onChange
for actions triggered during initialization.https://codesandbox.io/s/4zjv035mo9
I took your example and wrapped it in two outer states:
setup
andmain
. I also added aname
field to the context that defaults to"unset"
. Setup has anonEntry
action that updatesname
, and then an immediate transition tomain
. If you look at the output,name
doesn’t get updated as expected. But if you uncomment themachine.service.start
call on line 86, the state does update.If you leave the
start
call commented and click one of the tick buttons, you can see thatname
does update. So the state machine is holding the correct state, it just isn’t notifying react that the state context has changed during initialization.