If I need the result of using const db = getFirestore()
or const auth = getAuth(app)
etc. in multiple components, I should:
Whenever I need, rewrite these lines in each component const db = getFirestore()
or const auth = getAuth(app)
etc, or
Only call them at the top level of the App component and then pass them as props to child components to avoid multiple calls?
I feel option 1 is easier to code, but may result in a performance penalty. What is the correct way to do this in React/Firebase coding?
getFirestore(...)
,getAuth(...)
and similar calls are simple local calls that initialize some basic objects from the configuration. There's no harm in calling them in multiple places.That said, I'd recommend passing
app
to all of them, or to none, unlike what the code in your question does now.So, either get all services from the default application:
or Get all content from the specified application:
But not a mix of these.