This README explains how to connect your React (Vite) app to a real-time backend using Firebase Firestore. You can directly copy–paste and follow these steps for hackathons, demos, or production-ready prototypes.
✔ Enables real-time data updates (no refresh) ✔ User input updates dashboard instantly ✔ Suitable for medical analytics, live monitoring, dashboards ✔ No backend server required
- React (Vite)
- Firebase Firestore (Real-Time Database)
- Tailwind CSS (UI)
User Input
↓
Firebase Firestore (Real-Time)
↓
React App Listener (onSnapshot)
↓
Dashboard / Charts Update Instantly
- Go to Firebase Console
- Click Create Project
- Project name:
medalgo-realtime - Disable Google Analytics (optional)
- Click Create
- Open Project Settings
- Click </> Add Web App
- App name:
medalgo - Register App
- Copy the Firebase Config
Example:
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};- Firebase Console → Firestore Database
- Click Create Database
- Choose Test Mode
- Select nearest region
Open terminal in your project root:
npm install firebase📁 src/firebase.js
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID"
};
const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);Example inside App.jsx
import { useState } from "react";
import { collection, addDoc } from "firebase/firestore";
import { db } from "./firebase";
function App() {
const [value, setValue] = useState("");
const sendData = async () => {
await addDoc(collection(db, "liveData"), {
value: Number(value),
timestamp: Date.now()
});
setValue("");
};
return (
<div className="p-6">
<input
type="number"
value={value}
onChange={(e) => setValue(e.target.value)}
className="border p-2 mr-2"
placeholder="Enter value"
/>
<button
onClick={sendData}
className="bg-blue-600 text-white px-4 py-2"
>
Send
</button>
</div>
);
}
export default App;import { useEffect, useState } from "react";
import { collection, onSnapshot } from "firebase/firestore";
import { db } from "./firebase";
const [liveValues, setLiveValues] = useState([]);
useEffect(() => {
const unsubscribe = onSnapshot(collection(db, "liveData"), (snapshot) => {
const data = snapshot.docs.map(doc => doc.data());
setLiveValues(data);
});
return () => unsubscribe();
}, []);✔ Data updates instantly ✔ No refresh required
{liveValues.map((item, index) => (
<p key={index}>Live Value: {item.value}</p>
))}npm install
npm run devOpen:
http://localhost:5173
- Live patient vitals
- Real-time risk score calculation
- Instant dashboard updates
- Emergency monitoring
- Hackathon demos
✔ Real-time system ✔ No fake data refresh ✔ Scalable ✔ Industry-relevant
- Connect live data to charts
- Add multiple inputs (BP, HR, Age)
- Add medical risk algorithms
- Authentication (doctor / patient)
✔ Firebase provides real-time connection ✔ Easy to implement ✔ No backend server needed ✔ Perfect for MedAlgo & hackathons
📌 You can copy–paste this README directly into your project.