hunk.code_window:     }
       child.send(event);
     }
     /**
      * Returns the next state given the interpreter's current state and the event.
      *
  
hunk.labels: keep keep replace keep keep keep keep
hunk.after_edit:     target.send(event);
  
hunk.file_path: src/interpreter.ts
hunk.type: replace
file: import React, { useState, useMemo, useEffect, useRef } from 'react';
  import { interpret } from 'xstate/lib/interpreter';
  
  export function useMachine(machine, log) {
    const [current, setCurrent] = useState(machine.initialState);
    const service = useMemo(
      () =>
        interpret(machine)
          .onTransition(state => {
            log && console.log('CONTEXT:', state.context);
            setCurrent(state);
          })
          .onEvent(e => log && console.log('EVENT:', e))
          .start(),
      []
    );
  
    useEffect(() => {
      return () => service.stop();
    }, []);
  
    return [current, service.send];
  }
  