Touk
Touk

Reputation: 129

Infinite loop inside useEffect while trying to use Firebase

I'm building an app to write down values for electrical and gas meter : https://n3g.gitlab.io/react-conso-energie/

If you check the console, you'll see an infinite print of a console.log.

Here's the file where this magic happen : https://gitlab.com/n3g/react-conso-energie/-/blob/br/V2/src/ListingExpansionPanels.js

I don't understand why my useEffet (line 19) is fired infinitely although I've add [dbRef] check at line 36..

In my imagination, it would be fired only if I add or remove things in my database ?

Thanks you if someone can take a look because I'm struggeling with this since few weeks. I do believe I'm over complicate things when I try to fecth data from my database..

Upvotes: 0

Views: 152

Answers (1)

Try wrapping firebase.database().ref('2020') with useRef hook like this:

const dbRef = useRef(firebase.database().ref('2020'));

And remove dbRef from useEffect deps array, change usage from dbRef to dbRef.current

Upvotes: 1

Related Questions