diff --git a/src/App.js b/src/App.js
index 3171cb8..f585876 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,7 +1,7 @@
import { FirebaseConfig } from "./config/Config"
import { initializeApp } from "firebase/app"
import { Routes, Route } from "react-router-dom"
-import { useState } from "react"
+import { useState, useEffect } from "react"
import { getAuth,
createUserWithEmailAndPassword,
onAuthStateChanged,
@@ -52,6 +52,15 @@ function App() {
/// application states
const [nav, setNav] = useState(navItems)
const [auth, setAuth] = useState(false)
+ const [data, setData] = useState([])
+ const [ fetching , setFetching ] = useState( false )
+
+ useEffect( () => {
+ if( data.length === 0 ) {
+ readData()
+ setFetching( true )
+ }
+ }, [data])
// authentication observer
@@ -106,12 +115,13 @@ const signIn = (email, password) => {
// function to get data
const readData = async () => {
const querySnapshot = await getDocs( collection(FBdb, "books") )
- let data = []
+ let listdata = []
querySnapshot.forEach( (doc) => {
let item = doc.data()
item.id = doc.id
- data.push( item )
+ listdata.push( item )
})
+ setData( listdata )
}
@@ -120,7 +130,7 @@ const readData = async () => {
- } />
+ } />
} />
} />
} />