Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/wobsoriano/solid-firebase

Solid primitives for Firebase v9.
https://github.com/wobsoriano/solid-firebase

firebase solid solid-js

Last synced: about 1 month ago
JSON representation

Solid primitives for Firebase v9.

Awesome Lists containing this project

README

        


solid-firebase

# solid-firebase

Solid primitives for Firebase.

> ⚠️ This package only works with [Firebase 9 or above with modular style](https://firebase.google.com/docs/web/modular-upgrade).

## Quick start

Install it:

```bash
npm install firebase solid-firebase
```

Configure firebase app:

```tsx
import { render } from 'solid-js/web'
import { initializeApp } from 'firebase/app'
import { FirebaseProvider } from 'solid-firebase'
import App from './App'

const app = initializeApp({ projectId: 'MY PROJECT ID' })

render(
() => (



),
document.getElementById('root'),
)
```

## Primitives

The primitive [useFirebaseApp](https://github.com/wobsoriano/solid-firebase/blob/master/packages/lib/src/hooks/useFirebaseApp.tsx) gives you access to the initialized firebase app.

### Authentication

[useAuth](https://github.com/wobsoriano/solid-firebase/blob/master/packages/lib/src/hooks/useAuth.tsx) is a [Firebase Auth](https://firebase.google.com/docs/auth) binding to easily react to changes in the users' authentication status.

```tsx
import { Match, Switch } from 'solid-js'
import { GoogleAuthProvider, getAuth, signInWithPopup } from 'firebase/auth'
import { useAuth, useFirebaseApp } from 'solid-firebase'

function Login() {
const app = useFirebaseApp()
const signIn = () => signInWithPopup(getAuth(app), new GoogleAuthProvider())

return Sign In with Google
}

function App() {
const app = useFirebaseApp()
const state = useAuth(getAuth(app))

return (
}>

Loading...










)
}
```

### Cloud Firestore

[useFirestore](https://github.com/wobsoriano/solid-firebase/blob/master/packages/lib/src/hooks/useFirestore.tsx) is a [Cloud Firestore](https://firebase.google.com/docs/firestore) binding that makes it straightforward to always keep your local data in sync with remotes databases.

```tsx
import { Match, Switch, createMemo, createSignal } from 'solid-js'
import { collection, getFirestore, limit, orderBy } from 'firebase/firestore'
import { useFirebaseApp, useFirestore } from 'solid-firebase'

function App() {
const app = useFirebaseApp()
const db = getFirestore(app)
const todos = useFirestore(collection(db, 'todos'))

// or for doc reference
const todo = useFirestore(doc(db, 'todos', 'todo-id'))

// you can also use an accessor for reactive query
const [postsLimit] = createSignal(10)
const postsQuery = createMemo(() => query(
collection(db, 'posts'),
orderBy('createdAt', 'desc'),
limit(postsLimit())
))
const posts = useFirestore(postsQuery)

return (


Loading...




An error occurred.







)
}
```

### Realtime Database

[useDatabase](https://github.com/wobsoriano/solid-firebase/blob/master/packages/lib/src/hooks/useDatabase.tsx) is a [Realtime Database](https://firebase.google.com/docs/database) binding that makes it straightforward to always keep your local data in sync with remotes databases.

```tsx
import { Match, Switch } from 'solid-js'
import { getDatabase, ref } from 'firebase/database'
import { useDatabase, useFirebaseApp } from 'solid-firebase'

function App() {
const app = useFirebaseApp()
const db = getDatabase(app)
const todos = useDatabase(ref(db, 'todos'))

return (


Loading...




An error occurred.







)
}
```

### Cloud Storage

[useDownloadURL](https://github.com/wobsoriano/solid-firebase/blob/master/packages/lib/src/hooks/useDownloadURL.tsx) is a hook that wraps the [getDownloadURL](https://firebase.google.com/docs/storage/web/download-files#download_data_via_url) method of [Cloud Storage](https://firebase.google.com/docs/storage).

```tsx
import { Match, Switch } from 'solid-js'
import { getStorage, ref } from 'firebase/storage'
import { useDownloadURL, useFirebaseApp } from 'solid-firebase'

function App() {
const app = useFirebaseApp()
const storage = getStorage(app)
const data = useDownloadURL(ref(
storage,
'images/yourimage.jpg',
))

// or with an accessor
const [location] = createSignal('images/yourimage.jpg')
const downloadRef = createMemo(() => ref(storage, location()))
const data = useDownloadURL(downloadRef)

return (


Download URL: Loading...




Error: {data.error?.name}




pic


)
}
```

## License

MIT