Google Sheets JSON for a React app
Call the API from a server route, and let the React side call your route.
import { useEffect, useState } from "react";
export function useRows(path) {
const [rows, setRows] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
fetch(path)
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(r.status))))
.then(setRows, setError);
}, [path]);
return { rows, error, loading: !rows && !error };
}
Point path at your own endpoint, such as /api/products, which calls https://sheetlatch-api.quietlathe.com/v1/SHEET_ID/Products with the key in a server-side environment variable.
Early access. SheetLatch opens soon. Join the early-access list and we will email you once when it does. Planned free plan: 1,000 requests a month. SheetLatch is not affiliated with Google.