Skip to content

Instantly share code, notes, and snippets.

View georgiarnaudov's full-sized avatar

Georgi Arnaudov georgiarnaudov

  • Plovdiv, Bulgaria
View GitHub Profile
@pflevy
pflevy / useDatabaseEntry.js
Created September 8, 2019 13:50
Creating custom react hooks. Real-time firebase database entry listener example. Custom hook file.
import { useEffect, useState } from "react";
import firebase from "./database";
export const useDatabaseEntry = entry => {
const [data, setData] = useState([]);
useEffect(() => {
const ref = firebase.database().ref(entry);
ref.on("value", snapshot => {
const array = [];
// For each data in the entry