@use-firebase/database

A custom React Hook that provides a declarative interface for Firebase Database.

Usage no npm install needed!

<script type="module">
  import useFirebaseDatabase from 'https://cdn.skypack.dev/@use-firebase/database';
</script>

README

@use-firebase/database

A custom React Hook that impliments Firebase's Database object.

npm version All Contributors

Installation

$ npm i @use-firebase/database

or

$ yarn add @use-firebase/database

Currently only useValue for a single database ref is supported. Complete support is planned.

API

useValue

For now, here is a basic setup. This will likely change in the future.

const [value, setValue] = useValue(path);

Parameters

Here are the parameters that you can use.

Parameter Description
path A string path to the value in Firebase.

Return

useValue returns a useState compatible array that you can deconstruct into value and setValue.

Parameter Description
value The value from the Firebase database at path. If the path is invalid, or the data is not yet read from thje cloud, a null is returned.
setValue A function that accepts a single patameter that is the data sent to Firebase. It returns a promise that resolves when the data is saved in the cloud. value will immediately reflect the new value from calling setValue (i.e. no round trip required to see a new value).

Example

TODO

Live demo

TODO

License

MIT Licensed