Fetching the Catalog

Fetching BookNest's Catalog Data

The practice API's GET /books?page=0&limit=12 slices its 60 books and adds nextPage and total. Run it with node api/server.mjs next to Metro, and set EXPO_PUBLIC_API_URL=http://10.0.2.2:8150 in .env (a physical phone needs your computer's LAN address instead). On a fresh install, with nothing persisted, BookNest's first launch logged:

Output of 166
 LOG  catalog: 0 books, status pending, fetch idle
 LOG  path: /
 LOG  query cache restored
 LOG  catalog: 0 books, status pending, fetch fetching
 LOG  catalog: 12 books, status success, fetch idle
16:11:07 GET /books?page=0&limit=12 200

The query waited for the persister to finish restoring (nothing to restore yet), then fetched page 0 once, even though the screen rendered several times. Put together, BookNest now reads the catalog, book details and favorites through TanStack Query 79,069 , the cart through the persisted Zustand 58,763 store, and the user through a small context:

BookNest's catalog loaded page by page from the API, and a book with its saved favorite and cart quantity
BookNest's catalog loaded page by page from the API, and a book with its saved favorite and cart quantity

The cart badge counts four copies of Salt and Saffron, kept across every restart in this section. Three habits keep this healthy as BookNest grows: query keys come only from keys, components read the store only through selectors, and nothing fetched from the server is copied into Zustand.