concept select bookable in category react

appears as: selected bookable, The selected bookable
React Hooks in Action

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

#D Hard-code the index of the selected bookable

In chapter 6, we left the BookablesList component doing double duty: displaying a list of bookables for the selected group and displaying details for the selected bookable. Figure 7.7 shows the component with the list and details visible.

Figure 7.7 The previous BookablesList component, from Chapter 6, showed the list of bookables and the details of the selected bookable

The component managed all of the state: the bookables, the selected group and the selected bookable, and flags for displaying details, Presentation Mode, loading state and errors. As a single function component with no child components, all of the state was in local scope and available to use when generating the returned UI. But, toggling the Show Details checkbox would cause a re-render of the whole component and we had to think carefully about persisting timer ids across renders when in Presentation Mode.

Listing 7.11 Putting the selected bookable in the BookablesView component
import React, {useState, Fragment} from "react";
 
import BookablesList from "./BookablesList";
import BookableDetails from "./BookableDetails";
 
export default function BookablesView () {
  const [bookable, setBookable] = useState();                            #A
 
  return (
    <Fragment>
      <BookablesList bookable={bookable} setBookable={setBookable}/>     #B
      <BookableDetails bookable={bookable}/>                             #C
    </Fragment>
  );
}