Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jackall3n/next-firestore


https://github.com/jackall3n/next-firestore

Last synced: 4 days ago
JSON representation

Awesome Lists containing this project

README

        

# next-firestore 🔥


NPM Version
Package License
NPM Downloads

## 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 (



)
}
```