cassiozen / useStateMachine

The <1 kb state machine hook for React
MIT License
2.38k stars 47 forks source link

Suggestion: Have an explicit initial event? #60

Closed devanshj closed 3 years ago

devanshj commented 3 years ago

While typing I was confused why and in what cases the event would be undefined. Only when I was rewriting I realized that the initial event is undefined, which is not that explicit at it's intent.

Libraries often have their initial event, like xstate has "xstate.init", redux has "@@​INIT" afaik, storeon also has "@​init". It's better to have event: { type: "FOO" } | { type: $$initial } rather than have event?: { type: "FOO" }. So I'd suggest there should be an explicit initial event, perhaps a symbol would be good.

cassiozen commented 3 years ago

Agreed. I will add it as an item on the devanshj:rewrite branch. We can than decide who will tackle it (I could probably give it a shot)