Connect your React Native app to Supabase with our step-by-step guide. Learn to set up an account, create a database schema, install the client, and fetch data seamlessly.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Supabase Account
Step 2: Create Database Schema
users
table:CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR NOT NULL,
email VARCHAR NOT NULL
);
Step 3: Initialize React Native Project
npm install -g react-native-cli
npx react-native init SupabaseProject
cd SupabaseProject
Step 4: Install Supabase Client
npm install @supabase/supabase-js
Step 5: Connect Supabase with React Native
supabaseClient.js
.import { createClient } from '@supabase/supabase-js';
const SUPABASE_URL = 'https://your-project-id.supabase.co';
const SUPABASE_ANON_KEY = 'your-anon-key';
export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
Replace 'https://your-project-id.supabase.co'
and 'your-anon-key'
with your actual Supabase URL and API key obtained from the Supabase dashboard.
Step 6: Fetch Data from Supabase
App.js
file.supabaseClient.js
.users
table and display it in your React Native app:import React, { useEffect, useState } from 'react';
import { View, Text, FlatList } from 'react-native';
import { supabase } from './supabaseClient';
const App = () => {
const [users, setUsers] = useState([]);
useEffect(() => {
const fetchUsers = async () => {
const { data, error } = await supabase
.from('users')
.select('*');
if (error) console.log('Error fetching users:', error);
else setUsers(data);
};
fetchUsers();
}, []);
const renderItem = ({ item }) => (
<View>
<Text>Username: {item.username}</Text>
<Text>Email: {item.email}</Text>
</View>
);
return (
<FlatList
data={users}
keyExtractor={(item) => item.id.toString()}
renderItem={renderItem}
/>
);
};
export default App;
Step 7: Run Your React Native App
npx react-native run-android
npx react-native run-ios
Following these steps, you should have a React Native app connected to a Supabase back-end, able to display data from the users
table. Adjust the code as needed to fit the specific requirements of your project.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.