How to Build Self Confidence Little By Little

Where does confidence come from? Most people would say it comes naturally but it comes from experience. Experience helps you learn so much about the world and about yourself in so many ways. The more…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Using Firebase With React Context

Now head on over to the project settings, and select “Config” under “Firebase SDK snippet”. Take a note of these values because we will need them soon.

Next, create a react app and install firebase from npm

We will be wrapping the Firebase library in a class that will give access to only the functions that are needed. This class will also perform initialization with the config variables when it is instantiated. In this example, I will only be using the Realtime Database function, however, the process to use other functionality such as Auth or Cloud Firestore is as simple as adding another line to the class.

The useFirebase hook provides an easy way to grab the value of the nearest FirebaseContext provider. If there is no context provider where the hook is used, this will throw so that issues are caught early.

With the context defined, it can now be used within the react application. In App.js:

In this simple example, it’s easy to see the benefit of using the context. Each child component can simply just pull the Firebase instance from the context provider instead of having it get drilled down.

Cheers

Add a comment

Related posts:

Kids Making Music is Kids Creating Culture

While doing some last minute Christmas shopping last December, I was struck by how many children’s toys on the shelves are essentially TV or tablet screens. Lights flash, sounds blare, and pieces…

Dynamics 365 CE SDK

Dynamics 365 CE SDK içeriğinde önemli noktaların Türkçe çevirileri, teknik yorumları ve .NET örneklerini bu yazı dizisinde bulabilirsiniz.

Magnetic Switch

She tried a switch to turn it on. Aside from a click, there were no signs of life. The metal creatures appearance pleased Copper. She wasn’t sure why. She dragged it out of the earth and gave it a…