Loading homepage
Implement useQuery(url, onChange?) as a framework-independent function that fetches JSON and returns the current data, loading, and error states.
This is a plain JavaScript/TypeScript function, not a React Hook or a TanStack Query clone. Open usage-examples.md in the editor for JavaScript, TypeScript, React, Vue, and Angular usage examples.
Input: Call useQuery("/api/users") Output: { data: null, loading: true, error: null } immediately.
Input: HTTP 200 with JSON [{ id: 1 }] Output: { data: [{ id: 1 }], loading: false, error: null } after completion.
Input: HTTP 404 Output: { data: null, loading: false, error: Error("HTTP 404") } after completion.
Input: Network rejection Error("Offline") Output: { data: null, loading: false, error: Error("Offline") } after completion.
useQuery(url, onChange?) returns a live state object immediately. onChange receives one settled snapshot. Usage examples are supplied as a readable editor file. Tests mock fetch; no real API is called.