react-firebase-fns
react-firebase-fns
Firebase's JavaScript SDK turned into declarative React components.
Components
Value
Watch a Realtime Database value. Equivalent to https://firebase.google.com/docs/database/web/read-and-write#listen_for_value_events
<Value path="/realtime/database/path"> {/* val is the value from dataSnapshot.val() */}</Value>
List
Watch a Realtime Database list. Equivalent to https://firebase.google.com/docs/database/web/lists-of-data#listen_for_child_events
<List path="/realtime/database/list" orderBy="child | key | value" // orderBy="child" is optional when orderByChild is set, but orderByChild is required when orderBy="child" // orderByChild is ignored when orderBy is set to anything other than child orderByChild="child key or path" startAt="value" startAtKey="optional key" endAt="value" endAtKey="optional key" equalTo="value" equalToKey="optional key" limitToFirst="number" limitToLast="number"> {/* list is updated on child_added, child_removed, and child_changed events */}</List>
User
A user state provider for Authentication. Equivalent to https://firebase.google.com/docs/auth/web/start#set_an_authentication_state_observer_and_get_user_data
Unlike other components, User is a React Context with a Provider and Consumer.
<UserProvider> <SomeComponents> <DeeplyNested> <UserConsumer> {/* user will be undefined if not logged in */} </UserConsumer> </DeeplyNested> </SomeComponents> </UserProvider>
Upload task
The the progress for a Storage upload. Equivalent to https://firebase.google.com/docs/storage/web/upload-files#monitor_upload_progress
const uploadTask = storageRef// ...some lines later<UploadTask uploadTask=uploadTask> <progress value=bytesTransferred max=totalBytes></progress></UploadTask>
Missing components?
The entire SDK won't be exposed in this library. Only the parts with a realtime aspect make sense.
The following is not implemented yet. Make a pull request? ❤️
Realtime Database
Cloud Firestore
Installation
npm install --save react-firebase-fns
Global Firebase
Configure Firebase as usual and react-firebase-fns
will use the global Firebase with:
Provided Firebase application
You can also pass in a Firebase application.
const Value List User =
Roadmap
- add render prop
- add component prop
Inspired by react-fns.
Ronald Chen @pyrolistical