React, Redux & Firebase App Tutorial #17 - Connecting Redux to Firebase

Net Ninja · Beginner ·🌐 Frontend Engineering ·7y ago
Skills: React90%

Key Takeaways

Connects Redux to Firebase using third-party packages to interact with Firestore database in a React application

Full Transcript

all right then gangs so then so far we have created our Firebase project and we've also created a fire store right here added a project collection and a document to that project collection we've also in our react app over here created a config file for our Firebase setup and we've exported that Firebase object at the bottom in case we need this somewhere else inside the application so now what we want to do is somehow find out a way to add a new project to our fir store database from our application when we submit the form on the website now we already have a create project action over here and this is where we can make some kind of asynchronous call to do that we just need to finish this up so we want to interact with the fire store here to add a new project so how do we do that exactly well we could use the normal Firebase Library we've just installed to do that that's absolutely fine but instead what I'd like to do is install a couple of packages specifically designed for Redux and Firebase to work together in Synergy and these packages are called react Redux Firebase and Redux fir store now react Redux Firebase that provides bindings to the Firebase Service as a whole and Redux fir store provides Redux bindings for fir store databases in particular in short installing these two packages means that we'll be able to use the Firebase API to interact with our database inside these action creators and it also means that we'll be able to sync up our firestore database with our react store so let's install these packages first of all open up your terminal then npm install and first of all react Redux Firebase oops spell this correctly and then Redux hyphen fir store okay so install both of those and once those are installed we can now use them inside our project so just like we added thk functionality to our store we have to do something similar with these packages so what I'm going to do is open up index.js where we create our store right here and I'm going to import something from each one of these packages so first of all I'm going to import get fir store and this will be from Redux hyphen fir store then I'm going to import get Firebase from react Redux Firebase Okay so we've imported both of these things right here and what we want to do is use them so that we can access the Firebase or fire store API inside this function right here and the way we can do that is by tacking them on to this thing right here so what we can do is actually use a function on this thunk called with extra arguments and this extra argument is going to be an object and inside this object we can pass in different properties now the properties I want to pass in are these two things right here get fire store and get Firebase so let's add both of those in so I'll say get Firebase first of all and then get fir store so now what will happen is inside this thing over here this function because thk allows us to return a function we get an extra argument that's what this thing does over here with extra argument okay it allows us to pass in an extra argument over here which is an object now I want to destructure two properties from that object that we applied over here we applied these two properties to that object get Firebase and get fire store which are going to equal these things over here so what we can do is just destructure those inside curly braces so I could say get Firebase and get fire store and then we can use these two objects right here to interact with our Firebase and fire store but but if we did that at the minute then this is not going to work because these two things don't actually know about our project they don't know the details of it yeah we created in the Firebase config over here all of this setup and we connected to the Firebase project but at the minute we're not doing anything else with it we're not passing that information on to Redux or these things over here so they don't really know about our project so somehow we have to tell these two things these two packages over here Redux fire store and react Redux Firebase we have to tell those things that this is our Firebase config I want you to connect to this Firebase project for us now the way we do that is by using some store enhancers inside this now we've talked a little bit about store enhancers this thing right here this thk is a middleware and when we apply middleware over here like this this returns a store enhancer so we can add multiple store enhancers to a store and the way we do that is by using compose so much like inside our reducers when we have a root reducer which combines several reducers together we can do a similar thing over in the store we can combine several store enhancers together and we do that using a method called compose so first of all let's import compose and we do that from the Redux Library so compose over there then what I'd like to do is before apply middleware I'm just going to say compose and this is a function now let's get rid of the second bracket because this apply middleware this first thing right here this is going to be the first door enhancer that we're composing together with other things so let us now close this off like so that's the composed thing over there then we're closing off create store so that's the first store enhancer right there we want to ose two more so I'd like to now import Redux fir store from Redux fire store and also react Redux Firebase from react Redux Firebase and these are the other two store enhancers so let's add them into the compos method so first of all this thing Redux fire store like so which is a function and then also this thing react Redux Firebase let's copy that and add that in too okay so we're adding in these store enhancers and that's enhancing our store with these packages right so that we can link the two together but we need to pass in our config for our F base in here so that when we're enhancing our store we're passing in that config and therefore when we use these things over here then these things know which project to connect to make sense so let's do that we need to import our config over here from this file so we'll say import FB config from and it's slash then into the config folder then FB config like so so now we can take this configuration and we can pass it into both of these like this all right then so now when we try to use the because we've passed that configuration into these store enhancers right here then these things know what to connect to and since these things now know what to connect to we can go ahead and use this thing get fir store in the next video to connect to our fire store and add a document to our collection

Original Description

Hey gang, in this React, Redux & Firebase tutorial we'll use a couple of third-party packages to connect to Firebase and Firestore from Redux. ---------------------------------------- 🐱‍💻 🐱‍💻 Course Links: + VS Code editor - https://code.visualstudio.com/ + GitHub repository (course files) - https://github.com/iamshaunjp/React-Redux-Firebase-App 🧠🧠 Other Helpful Playlists: + React & Redux Tutorial - https://www.youtube.com/playlist?list=PL4cUxeGkcC9ij8CfkAY2RAGb-tmkNwQHG + JavaScript for Beginners - https://www.youtube.com/playlist?list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET 🤑🤑 Donate + https://www.paypal.me/thenetninja 🎓🎓 Find me on Udemy + https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related Reads

📰
How I Added Browser-Based HEIC to JPG Conversion (No Server, No Upload)
Learn how to convert HEIC to JPG in the browser without server upload using heic2any
Dev.to · Rushikesh Lade
📰
Angular Signals in 2026: From Fundamentals to Architect-Level Patterns
Learn Angular Signals fundamentals and architect-level patterns to improve your Angular applications
Dev.to · Amanulla Khan
📰
How to embed a widget on any site without CSS collisions (Shadow DOM)
Learn to embed widgets on any site without CSS collisions using Shadow DOM, ensuring seamless integration and avoiding styling conflicts
Dev.to · Michael Yousrie
📰
Building a Simple Calculator with HTML, CSS, and JavaScript
Learn to build a simple calculator using HTML, CSS, and JavaScript to understand web development basics
Medium · JavaScript
Up next
Elementor Angie Ai Plugin Tutorial
Quick Tips - Web Desiign & Ai Tools
Watch →