Coding a Finite-State Machine in a React Hook