React, Redux & Firebase App Tutorial #12 - Adding Dummy Data

Net Ninja · Beginner ·🌐 Frontend Engineering ·7y ago

Key Takeaways

Adds dummy data to the Redux store and connects the project component to it

Full Transcript

alright then so I did say that you wouldn't see this diagram again but here it is rearing its ugly head once more but I just want to use it to explain how we're going to connect to our relook store and where we're going to get data from and how we're gonna sync our app with the redux door so this dashboard right here this is listing all of the projects right now we're not going to reach out and grab data from this thing right here we're going to grab it from the dashboard and this is our container component then what we'll do is pass the data as props to the project list and then to the project summary okay so that's what we're going to do in this tutorial but first of all we need to create that dummy data on our store so to do that let's go to the project reducer because we're going to create some dummy projects and in here what we'll need to do is create a projects property and this is going to be an array of different projects now I'm just gonna paste a series of objects in here but I'll show you what they are now so three objects each one has a unique ID a title and some content so three simple projects right so now when the application first starts and the reducers first run this is going to set the state equal to the initial state to begin with then it's going to return that now in the root reducer we combine the reducers right so the project reducer here all that information is going to be stored on the state on a project property all right so this stuff right here is going to be stored on a project property on the state now we want to access that from our dashboard component so let's save this first of all then head over to our dashboard component so let's get rid of these we don't need these reducers anymore and open up components and get the dashboard so now we want to connect to our store now we've seen how to do this in a previous tutorial series and it's as simple as importing connect which is a higher-order component from the react Redux library remember this is the glue library which glues redox to and that's what we're doing here we're connecting the two together we're going to connect this dashboard component with the redux tour so then down here this is where we can connect connect is a function which returns a higher-order component to take in the dashboard so now we need to somehow map our state from the store to the props in this component now we do that by creating a function and this function is going to be called map state to props so this function right here takes in the state of our store we have access to that and then what we can do is return down here an object and this object is gonna represent which properties are attached to the props of this component so then we can access them inside this component so we want to create a property called projects on the props now this is going to be on the state object then remember if we open up the reducers again go to the root reducer it's going to be on the project property of the state first of all so state project then inside that project object we have this property right here projects so that's what we want to access so project projects I hope that makes sense and that's what we're grabbing and we're attaching to a project property inside the props of this component so we need to pass this function as a parameter to connect so the connect function knows what to connect to what data to get from the store we're mapping that to our props object in here so now what we could do is access props to projects inside this component and it would get us this data okay all right then so first of all let us just console dot log and this dot props so if we save this now and view in a browser I'm on the dashboard over here now and we're going to inspect and go to console and we see the props object now down here we can see a project property because this is what we wanted that to be called on the props object and inside a we have access to those projects so we have the data now and what we need to do is take this data and we need to pass it down into the project list component right here so that that can access it and output the correct projects so let's just comment this thing out for a minute I'm going to use a bit of destructuring now to get the projects I'm going to say Const and then projects is equal to this dot props so that just grabs the projects object off the props you don't have to do this I just like to do this and then what we can do is pass those projects down as a prop into the project list component so projects equals projects these things right here and now we're passing them down into this component so let's open up that component project list now we have to receive those props inside this component so I'm going to use some destructuring directly in here to grab the project's like so and that's grabbing the project's property off the props that we receive inside this component and then what we can do is cycle through these projects right here and output a project summary for each individual project so let's get rid of these for now we don't need these anymore and instead what we'll do is map through the project now in previous tutorials I've done all of this stuff directly outside the return statement bot just for a change I'm gonna do it directly inside the return statement so I'm going to open up my curly braces and then I'm going to say projects double ampersand projects dot map and I'll explain this in a second each time around we take the project in a function and we'll do something so first of all why did I do this bit well if I just say projects dot map then we might not have any projects to begin with or until our component reaches out to an external database in the future we might not have any projects so by adding this at the start oops by adding this at the start is saying ok if we have projects then I want you to do this if we don't have projects then don't bother doing this map thing because there's nothing to output make sense so that's why we do this at the start okay then so we're mapping through the projects here and we're taking an individual project each time we cycle through the project array okay now what we want to do is output some JSX for each individual project so I can just return that directly in here like so and what we're going to do is return a project summary for each individual project right now we don't need to do that right there what we want to do now is pass down as a prop the individual project so we can pass that down like so we're grabbing the project that we're currently iterating across right there passing it down as a prop into project summary like that and the key is going to be the project ID so we can say project ID and then we'll close off that okay so basically what we're saying is we're taking the project as a prop we're cycling through those projects if we have some and then each time around what we're doing is returning some JSX were going to output a project summary which is this component and for each project summary we're passing down an individual project and assigning a key value so now inside the project summary we receive an individual project each time so what we can do instead of output in this text we could output dynamically project dot title now we don't have an author field or a time field just yet so we'll leave these as is but at least now the project title will be directly output so let's just save this and view this in a browser and now we can see the projects that we had in our store they are being output to the Dom over here so that's pretty cool right we've now connected our application to our Redux store and we're grabbing data inside our dashboard from that store and we're passing it down into the project list and the project summary components then outputting it to the Dom now in reality we don't really want to use dummy data like we have done we want to use some kind of external database and to do that we're going to have to start using ace Kronus cold and we're going to have to use that within redux somehow because redux is keeping track of our state of the application so in the next video I want to talk about how we can use asynchronous code with redux

Original Description

Hey gang, in this React, Redux & Firebase tutorial we'll add some dummy data to our redux store, then connect our projects component to the redux store. ---------------------------------------- 🐱‍💻 🐱‍💻 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 AI Lessons

Up next
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks
Watch →