concept isPresenting in category react

appears as: isPresenting
React Hooks in Action

This is an excerpt from Manning's book React Hooks in Action.

To model Presentation Mode for the BookablesList component, we add an extra state value for the reducer called isPresenting. We check that isPresenting is true before firing up any timers for Presentation Mode. The initial value of isPresenting is false but switches to true when the bookables load. Then, if the user selects a bookable or uses the Next button, the value switches back to false.

Switching off Presentation Mode when the user directly selects a bookable is easy to handle, just set isPresenting to false in the SET_BOOKABLE action. But, both a timer (in Presentation Mode) and the user (by clicking the Next button) can cause the movement from one bookable to the next, by dispatching the NEXT_BOOKABLE action. So, the NEXT_BOOKABLE action needs to know whether it’s a timer or a user dispatching it; it needs to know whether to stop presenting or not. You can see the reducer using the NEXT_BOOKABLE action’s payload to set isPresenting in listing 6.2.