https://github.com/jackall3n/next-firestore
https://github.com/jackall3n/next-firestore
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jackall3n/next-firestore
- Owner: jackall3n
- Created: 2022-05-30T16:12:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:46:47.000Z (about 2 years ago)
- Last Synced: 2025-02-19T21:35:01.565Z (10 months ago)
- Language: TypeScript
- Size: 45.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# next-firestore 🔥
## Blurb
A library dedicated to supporting Firebase + server-side rendering.
## Installation
```shell
npm install next-firestore
```
```shell
yarn add next-firestore
```
## Setup
### _app.js
```typescript jsx
import { getFirestore } from "@firebase/firestore";
import { FirestoreAppProvider } from "next-firestore";
const app = getFirestore()
function MyApp({ Component, pageProps }) {
return (
)
}
export default MyApp
```
## Usage
### Collection
```typescript jsx
import admin from 'firebase-admin';
import { FirestoreProvider, useFirestoreApp } from 'next-firestore';
// Create fetchers for collections and documents
const fetchers = {
projects: getCollection('projects')
}
function Page() {
// Get client side data, and subscribe to live updates
const [projects] = fetchers.projects.useData()
return (
There are {projects.length} projects!
)
}
export default async function getServerSideProps(context) {
// Get server side data
const projects = await fetchers.projects.get(admin);
return {
props: {
firebase: {
...projects
}
}
}
}
export default (props) => {
return (
)
}
```
### Document
```typescript jsx
import admin from 'firebase-admin';
import { FirestoreProvider, useFirestoreApp } from 'next-firestore';
const fetchers = {
project: getDocument('projects')
}
function Page() {
const { query } = useRouter();
const [project] = fetchers.project.useData(query.id)
return (
{project.name}
)
}
export default async function getServerSideProps(context) {
const id = context.query.id;
const project = await fetchers.project.get(id, admin);
return {
props: {
firebase: {
...project,
}
}
}
}
export default (props) => {
return (
)
}
```