How to use the reactfire.useDatabaseObject function in reactfire

To help you get started, we’ve selected a few reactfire examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prescottprue / generator-react-firebase / examples / react-firebase / src / routes / Account / components / AccountEditor / AccountEditor.js View on Github external
function AccountEditor() {
  const classes = useStyles()
  const firebase = useFirebaseApp()
  const auth = useUser()
  const accountRef = firebase.database().ref(`users/${auth.uid}`)
  const profileSnap = useDatabaseObject(accountRef)
  const profile = profileSnap.snapshot.val()

  function updateAccount(newAccount) {
    return firebase
      .updateProfile(newAccount)
      .then(() => accountRef.update(newAccount))
      .catch(error => {
        console.error('Error updating profile', error.message || error) // eslint-disable-line no-console
        return Promise.reject(error)
      })
  }

  return (
github FirebaseExtended / reactfire / sample / src / RealtimeDatabase.js View on Github external
const Counter = props => {
  const database = useDatabase();
  const ref = database().ref('counter');
  const increment = amountToIncrement => {
    ref.transaction(counterVal => {
      return counterVal + amountToIncrement;
    });
  };

  const { snapshot } = useDatabaseObject(ref);
  const counterValue = snapshot.val();

  return (
    <>
      <button> increment(-1)}&gt;-</button>
      <span> {counterValue} </span>
      <button> increment(1)}&gt;+</button>
    
  );
};