Skip to main content
Learn how to integrate Supabase with React to build modern single-page applications with authentication, real-time data, and file storage.

Why React + Supabase?

  • Hooks-based API for clean, reusable code
  • Real-time subscriptions for live updates
  • Type-safe with TypeScript
  • Zero backend configuration needed
  • Fast development with minimal boilerplate

Quick Start

1

Create a React App

Using Vite (recommended):
Or using Create React App:
2

Install Supabase

3

Set Up Environment Variables

Create .env (Vite) or .env.local (CRA):
For Create React App, use REACT_APP_ prefix instead of VITE_.
4

Create Supabase Client

Create src/lib/supabase.ts:

Authentication

Auth Context

Create an auth context to manage user state:

Login Component

Create a login form:

Database Operations

Fetching Data

Use hooks to fetch data:

Custom Hook for Data Fetching

Create a reusable hook:

Inserting Data

Create and insert records:

Real-time Subscriptions

Subscribe to database changes:

File Upload

Upload files to Supabase Storage:

App Structure

Put it all together:

Best Practices

Use Context for Auth

Manage authentication state globally with React Context.

Custom Hooks

Create reusable hooks for common Supabase operations.

Error Handling

Always handle errors and provide user feedback.

Loading States

Show loading indicators during async operations.

Cleanup Subscriptions

Unsubscribe from real-time channels when components unmount.

Next Steps

Build a Todo App

Complete tutorial with authentication

User Management

Add profile management

File Uploads

Handle file storage

Examples

Explore more examples