Suggestion: Less awkward way to pass context and event types
See original GitHub issueuseStateMachine is a curried function (Yummm tasty!) because TypeScript doesn’t yet support partial generics type inference. This workaround allows TypeScript developers to provide a custom type for the context while still having TypeScript infer all the types used in the configuration (Like the state & transitions names, etc…).
We no longer have this limitation with #36. We can have something like the following for context…
useStateMachine({
initial: "idle",
context: { foo: 1 } // I prefer "initialContext" but whatever xD
...
})
And something like this (what xstate v5 does), for events and context…
useStateMachine({
schema: {
context: createSchema<{ foo: number, bar?: number }>(),
event: createSchema<
| { type: "X", foo: number }
| { type: "Y", bar: number }
>(),
// I prefer "event" instead of "events" because the type is for event and not "events"
// (unions need to be named singular even though they seem plural)
// though "events" works too if that's more friendly
},
initial: "idle",
context: { foo: 1 }
...
})
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
7 Tricky Work Situations, and How to Respond to Them
Situation #5: You have to give negative or awkward feedback to someone you're close with. Tony is a purchaser at a chocolate factory....
Read more >Managing Difficult Classroom Discussions
This page provides tips and resources for managing heated or contentious conversations in the classroom.
Read more >12 Interactive Presentation Ideas Your Event Audience Will Love
Try these Interactive Presentation Ideas for Amazing Events: ... It's less awkward – When people are already moving in ways that don't feel...
Read more >AWS Lambda function handler in TypeScript
The AWS Lambda function handler is the method in your function code that processes events. When your function is invoked, Lambda runs the...
Read more >Examples Of Various Ways To Invite People To Hang Out
This article gives a variety of examples of different ways someone might ask a new potential friend to do something with them.
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
Cool so I’ll update the PR soon and it’ll be good to merge!
Oh, that looks pretty good. Let’s go with it.