const fetchMachine = Machine( { id: 'fetch', initial: 'idle', context: { results: [], retryCount: 0, }, states: { idle: { on: { FETCH: 'loading', }, }, loading: { invoke: { src: 'loadData', onDone: { target: 'success', actions: 'handleData' }, onError: 'failure', }, on: { RESOLVE: 'success', REJECT: 'failure', }, }, success: {}, failure: { after: { FETCH_DELAY: [ { target: 'loading', actions: 'increment', cond: 'withinLimit' }, { target: 'terminated' }, ], }, }, terminated: { type: 'final', }, }, }, { guards: { withinLimit: () => true }, actions: { handleData: assign({ results: (_, event) => event.data }), increment: assign({ retryCount: context => context.retryCount + 1 }), }, delays: { FETCH_DELAY: context => context.retryCount * 500, }, } )