text: /**
   * Copyright (c) Facebook, Inc. and its affiliates.
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE file in the root directory of this source tree.
   *
   */
  
  import {useState, Suspense} from 'react';
  import {ErrorBoundary} from 'react-error-boundary';
  
  import {useServerResponse} from './Cache.client';
  import {SelectedBookContext} from './SelectedBookContext.client';
  
  export default function Root({initialCache}) {
    return (
      <Suspense fallback={null}>
        <ErrorBoundary FallbackComponent={Error}>
          <Content />
        </ErrorBoundary>
      </Suspense>
    );
  }
  
  function Content() {
    const [selectedId, setSelectedId] = useState({selectedId: null});
    const response = useServerResponse(selectedId);
    return (
      <SelectedBookContext.Provider value={[selectedId, setSelectedId]}>
        {response.readRoot()}
      </SelectedBookContext.Provider>
    );
  }
  
  function Error({error}) {
    return (
      <div>
        <h1>Application Error</h1>
        <pre style={{whiteSpace: 'pre-wrap'}}>{error.stack}</pre>
      </div>
    );
  }
  