Query a Basalt table from a single-page React app built with Vite.
- Install the client
npm install @basalt/client - Create a client
src/basalt.ts import { createClient } from '@basalt/client' export const basalt = createClient( import.meta.env.VITE_BASALT_URL, import.meta.env.VITE_BASALT_PUBLISHABLE_KEY, ) - Read rows in a component
src/App.tsx import { useEffect, useState } from 'react' import { basalt } from './basalt' export default function App() { const [notes, setNotes] = useState<any[]>([]) useEffect(() => { basalt.from('notes').select().then(({ data }) => setNotes(data ?? [])) }, []) return <ul>{notes.map((n) => <li key={n.id}>{n.body}</li>)}</ul> }
Never ship the secret key to a browser. It bypasses every row-level policy.