Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Available variables:
- // - Machine
- // - interpret
- // - assign
- // - send
- // - sendParent
- // - spawn
- // - raise
- // - actions
- // - XState (all XState exports)
- const fetchMachine = Machine({
- id: 'fetch',
- initial: 'idle',
- context: {
- retries: 1
- },
- states: {
- idle: {
- on: {
- FETCH: 'loading'
- }
- },
- loading: {
- on: {
- RESOLVE: 'success',
- REJECT: 'failure'
- }
- },
- success: {
- type: 'final'
- },
- failure: {
- on: {
- RETRY: {
- target: 'loading',
- actions: assign({
- retries: (context, event) => context.retries + 1
- })
- }
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement