// src/App.jsx import { useQuery } from "@tanstack/react-query"; import { useState } from "react"; // Simulates a slow network, same idea as Intermediate Ch6 Challenge 2. function fakeFetchUser(id) { const delay = id === "1" ? 1500 : 200; // id "1" resolves much slower return new Promise((resolve) => { setTimeout(() => resolve({ id, name: `User ${id}` }), delay); }); } function UserDisplay({ userId }) { const { data, isLoading } = useQuery({ queryKey: ["user", userId], // userId is part of the key queryFn: () => fakeFetchUser(userId), }); if (isLoading) return
Loading...
; return{data.name}
; } function App() { const [userId, setUserId] = useState("1"); return (