What are finite state machines?
If I were to ask you, my dear reader, to guess what finite state machines are, you would probably say they are related to managing state in applications. After all, this whole book is on that topic!
Funny thing is, finite state machines have nothing to do with applications; they have nothing to do with React or even programming at all. A finite state machine is a mathematical model of computation. It’s an abstract concept that can be applied to real-life objects or problems, and it represents a machine that can be in exactly one of a finite number of states at any given time. The predefined states can be changed from one to another in response to some user input. Traffic lights are an example of a simple finite state machine: a traffic light can be green, red, or yellow at any time, and it should never display two colors at once. Another example of a simple state machine is an elevator. The default state of an elevator is to stand still with...