React
Build React applications with Butterbase using the TypeScript SDK.
npm create vite@latest my-app -- --template react-tscd my-app && npm installnpm install @butterbase/sdkCreate client:
import { createClient } from '@butterbase/sdk';export const butterbase = createClient({ appId: import.meta.env.VITE_BUTTERBASE_APP_ID, apiUrl: import.meta.env.VITE_BUTTERBASE_API_URL,});Environment variables (.env.local):
VITE_BUTTERBASE_APP_ID=app_abc123VITE_BUTTERBASE_API_URL=https://api.butterbase.aiAuthentication component
Section titled “Authentication component”const handleSignIn = async () => { const { data, error } = await butterbase.auth.signIn({ email, password });};Data fetching
Section titled “Data fetching”const { data: posts } = await butterbase .from<Post>('posts') .select('*') .order('created_at', { ascending: false }) .limit(20);Auth state changes
Section titled “Auth state changes”const { unsubscribe } = butterbase.onAuthStateChange((event, session) => { setUser(session?.user ?? null);});return () => unsubscribe();const { url } = await butterbase.auth.signInWithOAuth({ provider: 'google', redirectTo: window.location.origin + '/auth/callback',});window.location.href = url;File uploads
Section titled “File uploads”const { data, error } = await butterbase.storage.upload(file);// Save data.objectId in your databaseDeploy
Section titled “Deploy”npm run buildcd dist && zip -r ../frontend.zip .Use create_frontend_deployment and start_frontend_deployment MCP tools to deploy.