i have a realtime database fetch data function. but, when I pass the function through "useeffect", the data I receive is printed 2 times.
Here is fetch and set function:
const SelectData = () => {
get(child(dbref, 'GamePot Users/')).then((snapshot) => {
if (snapshot.exists()) {
snapshot.forEach((doc) => {
let key = doc.key
const childData = doc.val()
const parsedChildData = JSON.parse(childData)
const user = {
id: key,
value: parsedChildData,
}
setUsers((prevUsers) => [...prevUsers, user])
})
}
})
}
and function running useEffect:
useEffect(() => {
SelectData()
}, [])
and show this img on my console print
thank you for you time.